Sitelet https://github.com/angular/angular/pull/39512
Skip to content

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

Closed
sebastianhaeni wants to merge 1 commit into
angular:masterfrom
sebastianhaeni:fix-jsonp-callback-ie11
Closed

sebastianhaeni wants to merge 1 commit into
angular:masterfrom
sebastianhaeni:fix-jsonp-callback-ie11

Conversation

@sebastianhaeni

@sebastianhaeni sebastianhaeni commented Oct 30, 2020 •

Copy link
Copy Markdown
Contributor

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
@josephperrott josephperrott added the area: common/http Issues related to HTTP and HTTP Client label Oct 30, 2020
@ngbot ngbot Bot added this to the needsTriage milestone Oct 30, 2020

@JiaLiPassion JiaLiPassion left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread packages/common/http/src/jsonp.ts Outdated
Comment thread packages/common/http/src/jsonp.ts Outdated
Comment thread packages/common/http/test/jsonp_spec.ts Outdated
Comment thread packages/common/http/src/jsonp.ts Outdated
@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
Comment thread packages/common/http/test/jsonp_spec.ts Outdated
Comment thread packages/common/http/src/jsonp.ts Outdated
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

@JiaLiPassion JiaLiPassion left a comment

Copy link
Copy Markdown
Contributor

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!

@JiaLiPassion
JiaLiPassion requested a review from jelbourn November 2, 2020 13:43

@mhevery mhevery left a comment

Copy link
Copy Markdown
Contributor

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

mhevery commented Nov 16, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
@pullapprove pullapprove Bot removed the area: common/http Issues related to HTTP and HTTP Client label 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