-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
Fix #12838: hook point for non-jQuery.ajax synchronous script fetch/execute in domManip #1051
Conversation
@@ -1666,8 +1666,10 @@ module( "ajax", { | |||
//----------- jQuery.getScript() | |||
|
|||
asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() { | |||
Globals.register("foobar"); |
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 really love this Globals
system :)
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.
Weird, I always test with the globals check on and this wasn't caught...
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.
Really? I just tried on Chromium and found several globals leaking in ajax tests; mostly from jsonp. I assumed it was already on your radar, but now I'm wondering if it's environment-specific.
…xecute in domManip
I expect this to change again, but it's a start.
Updated for the new year! Also, @jaubourg was right... putting this alongside ajax methods with which it has little in common is just begging for bug reports. So manipulation it is!
|
global: false, | ||
"throws": true | ||
}); | ||
jQuery._evalUrl( node.src ); |
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.
-1, No new API surface.
I'm sorry, but we need to find another 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.
It's not so much surface API as it is a simple hook. It's clearly marked as private (leading underscore).
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.
It is literally impossible to satisfy #12838 without new API surface. We may opt not to do it, but we will not find "another 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.
The only other way I see is to have a global core_evalUrl
variable and require anyone who wants to override the ajax module to do a custom build.
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.
The only other way I see is to have a global core_evalUrl variable and require anyone who wants to override the ajax module to do a custom build.
It's not practical. One would be expected to have a build without ajax and be able to use this build with whatever third party ajax lib (or none: $._evalURL = $.noop;
) they see fit, not have to rebuild a custom version per third-party. Having to override a variable in the closure at build time is overkill when a private overridable hook on the jQuery
object does the job perfectly.
I understand rick's reservations with this but I don't think we can offer a practical solution any other way. We can build jQuery without ajax now, so we should provide this hook.
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.
This looks like a script element being created and appended to the document.head
: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L34-L48 which would be invoked as a result of this call site: https://github.com/jquery/jquery/blob/master/src/manipulation.js#L335-L345
Is that incorrect?
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.
This looks like a script element being created and appended to the document.head: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L34-L48 which would be invoked as a result of this call site: https://github.com/jquery/jquery/blob/master/src/manipulation.js#L335-L345
Is that incorrect?
Yes, it is incorrect. Transport selection is a bit more involved than a simple one-on-one correspondance with a dataType. You missed the condition here: https://github.com/jquery/jquery/blob/master/src/ajax/script.js#L30
If it's not a crossDomain request, then ajax will continue searching for a suitable transport, until it reaches the one in xhr.js
. Effectively enabling synchronous same-domain requests. Executing scripts synchronously is mandatory for domManip
. It is, and always has been, broken for scripts of another domain but that's beside the point.
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.
What happens if the custom ajax lib doesn't do any of this? Can it just use a script element?
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.
You can't load a script using script tag injection synchronously.
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.
Yes, I know—thank you—but that's not what I asked.
I concede, let's pile more ugly "_" junk onto jQuery. Can't wait for the bug reports.
…xecute in domManip. Close jquerygh-1051. (cherry picked from commit 03db1ad)
This comment has been minimized.
This comment has been minimized.
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.
ok
I'm not thrilled about the name, but at least it's unambiguous.
Sizes - compared to master @ c2d6847