-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jQuery-UI widget breaks if using as a module #2015
Comments
Thanks for the report. I wonder what was the intention when Planning the fix for 1.13.1. |
The check causing an issue is: // Allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new constructor( options, element );
} So, basically, this is a duck-typing check to make sure we've got a widget instance and not another object. In most cases it works even now but if you save the constructor to a variable and call it directly, no Adding a check for For your case, before UI 1.13.1 is available, you can workaround the issue by changing your code to: import dialog from "jquery-ui/ui/widgets/dialog";
dialog.call($.ui, { ...options }, document.querySelector(".some-element"); or: import dialog from "jquery-ui/ui/widgets/dialog";
dialog.call(window, { ...options }, document.querySelector(".some-element"); Of course, I understand the feasibility of this depends on how many of these imports you have. 🙂 |
Due to the fact the widget factory code is now in strict mode, the check for being called without using the `new` keyword started breaking if you save the widget constructor to a variable before calling it: ```js var customWidget = $.custom.customWidget; customWidget( {}, elem ); ``` as then `this` is undefined and checking for `this._createWidget` crashes. Account for that with an additional check. Fixes jquerygh-2015
PR with a fix: #2019. |
Due to the fact the widget factory code is now in strict mode, the check for being called without using the `new` keyword started breaking if you save the widget constructor to a variable before calling it: ```js var customWidget = $.custom.customWidget; customWidget( {}, elem ); ``` as then `this` is undefined and checking for `this._createWidget` crashes. Account for that with an additional check. Fixes gh-2015 Closes gh-2019
jQuery UI 1.13.1 including a fix for this issue has been released: https://blog.jqueryui.com/2022/01/jquery-ui-1-13-1-released/. |
Hello, currently in our project we are using
jquery-ui
widgets as a separate modules like this:However in
1.13.0
we cant use widgets this way, now it fails to initialize a widget with an error:Uncaught TypeError: Cannot read properties of undefined (reading '_createWidget')
Even though you still able to use widgets "normally":
would be nice to fix this issue, especially since it looks unintended.
I believe problem was introduced in this commit: 70dae67
By adding
"use strict"
now this code: https://github.com/jquery/jquery-ui/blob/1.13.0/ui/widget.js#L80 fails, sincethis
isundefined
.The text was updated successfully, but these errors were encountered: