Skip to content
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(http): queue jsonp <script> tag onLoad event handler in microtask #39512

Closed
wants to merge 1 commit into from
Closed

fix(http): queue jsonp <script> tag onLoad event handler in microtask #39512

wants to merge 1 commit into from

Conversation

sebastianhaeni
Copy link
Contributor

@sebastianhaeni sebastianhaeni commented Oct 30, 2020

Fixes #39496

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #39496

Before this change, when trying to load a JSONP script that calls the JSONP callback inside a setTimeout function, it will fail in Internet Explorer 11 and EdgeHTML.

What is the new behavior?

This commit changes the event handler on the script tag to be queued with setTimeout. This ensures that the aforementioned browsers will first evaluate the loaded script calling the JSONP callback and only then run the load handler which does the tear down of the callback function and script tag.

Does this PR introduce a breaking change?

  • Yes
  • No

@google-cla google-cla bot added the cla: yes label Oct 30, 2020
@pullapprove pullapprove bot requested review from alxhub and mhevery October 30, 2020 18:14
@ngbot ngbot bot added this to the needsTriage milestone Oct 30, 2020
Copy link
Contributor

@JiaLiPassion JiaLiPassion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just like I commented in #39496, I think we can use a promise.then here to delay the execution.

Also could you add a test case to verify this fix?

@sebastianhaeni
Copy link
Contributor Author

@JiaLiPassion thank you for your comments!
I updated the PR with your proposed fix and added a test. I also verified this solution works in IE11, and it does.
Please have a look again.

packages/common/http/src/jsonp.ts Outdated Show resolved Hide resolved
packages/common/http/src/jsonp.ts Outdated Show resolved Hide resolved
packages/common/http/test/jsonp_spec.ts Show resolved Hide resolved
packages/common/http/src/jsonp.ts Outdated Show resolved Hide resolved
@sebastianhaeni sebastianhaeni changed the title fix(http): queue jsonp script tag event handler with setTimeout fix(http): queue jsonp <script> tag onLoad event handler in microtask Nov 1, 2020
Before this change, when trying to load a JSONP script that calls the JSONP callback inside a
microtask, it will fail in Internet Explorer 11 and EdgeHTML. This commit changes the onLoad cleanup
to be queued after the loaded endpoint executed any potential microtask itself. This ensures that
the aforementioned browsers will first evaluate the loaded script calling the JSONP callback and
only then run the cleanup inside onLoad.

Fixes #39496
Copy link
Contributor

@JiaLiPassion JiaLiPassion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the research and the fix!

Copy link
Contributor

@mhevery mhevery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: global-approvers

@mhevery
Copy link
Contributor

mhevery commented Nov 16, 2020

presubmit

@mhevery mhevery added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 16, 2020
@mhevery mhevery self-assigned this Nov 16, 2020
@atscott atscott closed this in 3926665 Nov 17, 2020
atscott pushed a commit that referenced this pull request Nov 17, 2020
…#39512)

Before this change, when trying to load a JSONP script that calls the JSONP callback inside a
microtask, it will fail in Internet Explorer 11 and EdgeHTML. This commit changes the onLoad cleanup
to be queued after the loaded endpoint executed any potential microtask itself. This ensures that
the aforementioned browsers will first evaluate the loaded script calling the JSONP callback and
only then run the cleanup inside onLoad.

Fixes #39496

PR Close #39512
@sebastianhaeni sebastianhaeni deleted the fix-jsonp-callback-ie11 branch November 20, 2020 11:28
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 21, 2020
@ngbot ngbot bot removed this from the needsTriage milestone Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSONP call fails in Internet Explorer 11 and Google Maps API
4 participants