-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Avoid using jquery if disabled using flag #16687
Avoid using jquery if disabled using flag #16687
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs to add the flag to packages/ember-environment/lib/env.ts
(like this one)...
60b6a16
to
03a33dd
Compare
@rwjblue Done! |
|
||
if (hasDOM) { | ||
jQuery = context.imports.jQuery; | ||
|
||
if (jQuery) { | ||
if (!jQueryDisabled && jQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how this is all connected, but I see a few modules importing jQuery
from this module, without checking for jQueryDisabled
. Before this change, there was no case possible that jQuery
was available while jQueryDisabled
is true. This is now possible, with the flag being false but the jQuery global still available. So should we override jQuery
to undefined
, if jQueryDisabled
is true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonihmig I think you might be right. Not if the user has explicitly disabled jQuery, Ember.$
will be undefined, even if jQuery happens to be included in the page in some other way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, I agree. I think that we need to change all of our guards to be checking jQueryDisabled
instead of the default export of this module.
tldr; it should absolutely be possible to tell Ember to treat jQuery as disabled even if window.$
is present...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue I already did in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! sorry :( I guess I thought we had more places that did the conditional...
import ActionManager from './action_manager'; | ||
import fallbackViewRegistry from '../compat/fallback-view-registry'; | ||
|
||
const HAS_JQUERY = jQuery !== undefined; | ||
const HAS_JQUERY = jQueryDisabled === false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should check for false
here (though I suppose it doesn't matter too much). In general we can trust that our jQueryDisabled
export will always be boolean and will encapsulate the proper "default to true, unless false" logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, any reason to not just use jQueryDisabled
in this file instead of making the second constant (HAS_JQUERY
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update:
if (jQuery) { |
ember.js/packages/ember/index.js
Line 564 in d97dcf7
Ember.$ = views.jQuery; |
(only setup Ember.$
if the jQuery is enabled)
49441f7
to
de4d6fd
Compare
Darn, sorry. My last change suggestion made the reexport tests fail
Should become: JQueryDisabled && ['$', 'ember-views', 'jQuery'] Then add a Sorry for the run around... |
de4d6fd
to
bae56f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, thank you!!
bae56f9
to
4aa5c84
Compare
I had to rebase because conflicts with the deprecation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a logging test is failing? kk
@simonihmig After rebasing over your deprecating a test is failing, but I think I've resolved conflicts correctly. Can you take a look to see if it's evident to your what is going on? |
if (jQuery) { | ||
assert.equal(messages[2], 'jQuery : ' + jQuery().jquery); | ||
if (jQueryDisabled) { | ||
assert.equal(messages[2], 'my-lib : ' + '2.0.0a'); | ||
assert.equal(messages[3], 'my-lib : ' + '2.0.0a'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cibernox this is related to the failing test, and it seems this line has to go into the else-block (which is when jQuery is enabled)! (as you have switched the order of the jQuery/no-jQuery blocks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, but it wasn't related with the failing test apparently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it did, as the previous failed test was related to the env output, and that seems to be passing now. But a deprecation test is now failing: https://travis-ci.org/emberjs/ember.js/jobs/384219437#L1562 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the only failure I was seeing before. That was the one I don't see why it is failing because of my changes
…ven if jquery is on the page.
4aa5c84
to
0e00d48
Compare
@cibernox Not sure what's going on. I would guess it's something about the changes around |
I just pushed a commit that should fix the remaining issue which was basically that we didn't properly identify the difference between jQuery being explicitly enabled (which should not receive a deprecation) and when it was implicitly enabled (which should receive a deprecation). |
@rwjblue thanks a lot! 👍 |
No description provided.