Skip to content

fix(docs-infra): fix angular.io on IE 11#41162

Closed
gkalpak wants to merge 2 commits into
angular:masterfrom
gkalpak:fix-aio-ie
Closed

fix(docs-infra): fix angular.io on IE 11#41162
gkalpak wants to merge 2 commits into
angular:masterfrom
gkalpak:fix-aio-ie

Conversation

@gkalpak

@gkalpak gkalpak commented Mar 10, 2021

Copy link
Copy Markdown
Member
  • fix(docs-infra): avoid unnecessarily loading Custom Elements ES5 shim:
    The custom elements spec is not compatible with ES5 style classes. This means ES2015 code compiled to ES5 will not work with a native implementation of Custom Elements. To support browsers that natively support Custom Elements but not ES2015 modules, we load @webcomponents/custom-elements/src/native-shim.js, which minimally augments the native implementation to be compatible with ES5 code.
    (See here for more details.)

    Previously, the shim was included in polyfills.ts, which meant it was loaded in all browsers (even those supporting ES2015 modules and thus not needing the shim).

    This commit moves the shim from polyfills.ts to a nomodule script tag in index.html. This will ensure that it is only loaded in browsers that do not support ES2015 modules and thus do not needed the shim.

    NOTE:
    This commit also reduces size of the polyfills bundle by ~400B (52609B --> 52215B).

  • fix(docs-infra): fix angular.io on IE 11:
    Previously, the angular.io app was broken on IE 11. In particular, pages that included Custom Elements would fail to load, because the Reflect.construct() method (which the Custom Elements ES5 shim relies on) was not available.

    This commit fixes this by loading the polyfill for Reflect.construct() on browsers that do not support ES2015 (including IE 11).

@gkalpak gkalpak added type: bug/fix comp: docs-infra target: patch This PR is targeted for the next patch release labels Mar 10, 2021
@gkalpak gkalpak added this to the docs-infra-aio-app milestone Mar 10, 2021
@google-cla google-cla Bot added the cla: yes label Mar 10, 2021
@mary-poppins

Copy link
Copy Markdown

You can preview 99eab12 at https://pr41162-99eab12.ngbuilds.io/.

gkalpak added 2 commits March 10, 2021 23:28
The custom elements spec is not compatible with ES5 style classes. This
means ES2015 code compiled to ES5 will not work with a native
implementation of Custom Elements. To support browsers that natively
support Custom Elements but not ES2015 modules, we load
`@webcomponents/custom-elements/src/native-shim.js`, which minimally
augments the native implementation to be compatible with ES5 code.
(See [here][1] for more details.)

Previously, the shim was included in `polyfills.ts`, which meant it was
loaded in all browsers (even those supporting ES2015 modules and thus
not needing the shim).

This commit moves the shim from `polyfills.ts` to a `nomodule` script
tag in `index.html`. This will ensure that it is only loaded in browsers
that do not support ES2015 modules and thus do not needed the shim.

NOTE:
This commit also reduces size of the polyfills bundle by ~400B
(52609B --> 52215B).

[1]: https://www.npmjs.com/package/@webcomponents/custom-elements#es5-vs-es2015
Previously, the angular.io app was broken on IE 11. In particular, pages
that included Custom Elements would fail to load, because the
`Reflect.construct()` method (which the Custom Elements ES5 shim relies
on) was not available.

This commit fixes this by loading the polyfill for `Reflect.construct()`
on browsers that do not support ES2015 (including IE 11).
@mary-poppins

Copy link
Copy Markdown

You can preview 7d487d3 at https://pr41162-7d487d3.ngbuilds.io/.

@gkalpak gkalpak marked this pull request as ready for review March 10, 2021 21:41
@gkalpak gkalpak requested a review from petebacondarwin March 10, 2021 21:44

@jessicajaniuk jessicajaniuk 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

reviewed-for: size-tracking

@gkalpak

gkalpak commented Mar 10, 2021

Copy link
Copy Markdown
Member Author

@jessicajaniuk, wait what? No 🍪? 😭 😭 😭

@petebacondarwin petebacondarwin 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.

I haven't bothered to test on IE. I trust that you did @gkalpak.
Reviewed-for: size-tracking

@jessicajaniuk jessicajaniuk 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.

🍪 I managed to find one!

@gkalpak gkalpak added the action: merge The PR is ready for merge by the caretaker label Mar 11, 2021
@AndrewKushnir AndrewKushnir added target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release labels Mar 11, 2021
AndrewKushnir pushed a commit that referenced this pull request Mar 11, 2021
Previously, the angular.io app was broken on IE 11. In particular, pages
that included Custom Elements would fail to load, because the
`Reflect.construct()` method (which the Custom Elements ES5 shim relies
on) was not available.

This commit fixes this by loading the polyfill for `Reflect.construct()`
on browsers that do not support ES2015 (including IE 11).

PR Close #41162
@AndrewKushnir

Copy link
Copy Markdown
Contributor

@gkalpak FYI this PR was merged to master only, since it had merge conflicts withe the patch branch (11.2.x). Could you please create a new patch-only version of this PR? Thank you.

@gkalpak gkalpak deleted the fix-aio-ie branch March 11, 2021 17:37
gkalpak added a commit to gkalpak/angular that referenced this pull request Mar 11, 2021
…angular#41162)

The custom elements spec is not compatible with ES5 style classes. This
means ES2015 code compiled to ES5 will not work with a native
implementation of Custom Elements. To support browsers that natively
support Custom Elements but not ES2015 modules, we load
`@webcomponents/custom-elements/src/native-shim.js`, which minimally
augments the native implementation to be compatible with ES5 code.
(See [here][1] for more details.)

Previously, the shim was included in `polyfills.ts`, which meant it was
loaded in all browsers (even those supporting ES2015 modules and thus
not needing the shim).

This commit moves the shim from `polyfills.ts` to a `nomodule` script
tag in `index.html`. This will ensure that it is only loaded in browsers
that do not support ES2015 modules and thus do not needed the shim.

NOTE:
This commit also reduces size of the polyfills bundle by ~400B
(52609B --> 52215B).

[1]: https://www.npmjs.com/package/@webcomponents/custom-elements#es5-vs-es2015

PR Close angular#41162
gkalpak added a commit to gkalpak/angular that referenced this pull request Mar 11, 2021
Previously, the angular.io app was broken on IE 11. In particular, pages
that included Custom Elements would fail to load, because the
`Reflect.construct()` method (which the Custom Elements ES5 shim relies
on) was not available.

This commit fixes this by loading the polyfill for `Reflect.construct()`
on browsers that do not support ES2015 (including IE 11).

PR Close angular#41162
gkalpak added a commit to gkalpak/angular that referenced this pull request Mar 11, 2021
…nts but not ES2015

Before angular#41162, angular.io was broken on IE 11 due to missing a polyfill
for an API (`Reflect.construct()`) needed by the Custom Elements ES5
shim. angular#41162 tried to fix this by loading the necessary polyfill
(`es.reflect.construct.js`) on browsers that do not support ES2015
modules (including IE 11).

It turns out that the fix in angular#41162 was itself broken, because the
`es.reflect.consruct.js` script (included directly in the page via a
`<script>` tag) was in CommonJS format (which cannot run in the browser
as is). By chance, this still allowed browsers that supported neither
Custom Elements nor ES2015 modules (such as IE 11) to work correctly as
a side-effect of loading the `@webcomponents/custom-elements` polyfill
after the Custom Elements ES5 shim (`native-shim.js`). However, on the
few browsers that natively support Custom Elements but not ES2015
modules, angular.io would still be broken.

This commit correctly fixes angular.io on all browsers by properly
bundling the polyfills and transpiling to ES5.

Implementation-wise, we use [esbuild][1] for bundling the polyfills (and
converting from CommonJS to a browser-compatible, IIFE-based format) and
[swc][2] for downleveling the code to ES5 (since `esbuild` only supports
ES2015+).

[1]: https://esbuild.github.io/
[2]: https://swc.rs/
AndrewKushnir pushed a commit that referenced this pull request Mar 11, 2021
…#41162) (#41184)

The custom elements spec is not compatible with ES5 style classes. This
means ES2015 code compiled to ES5 will not work with a native
implementation of Custom Elements. To support browsers that natively
support Custom Elements but not ES2015 modules, we load
`@webcomponents/custom-elements/src/native-shim.js`, which minimally
augments the native implementation to be compatible with ES5 code.
(See [here][1] for more details.)

Previously, the shim was included in `polyfills.ts`, which meant it was
loaded in all browsers (even those supporting ES2015 modules and thus
not needing the shim).

This commit moves the shim from `polyfills.ts` to a `nomodule` script
tag in `index.html`. This will ensure that it is only loaded in browsers
that do not support ES2015 modules and thus do not needed the shim.

NOTE:
This commit also reduces size of the polyfills bundle by ~400B
(52609B --> 52215B).

[1]: https://www.npmjs.com/package/@webcomponents/custom-elements#es5-vs-es2015

PR Close #41162

PR Close #41184
AndrewKushnir pushed a commit that referenced this pull request Mar 11, 2021
Previously, the angular.io app was broken on IE 11. In particular, pages
that included Custom Elements would fail to load, because the
`Reflect.construct()` method (which the Custom Elements ES5 shim relies
on) was not available.

This commit fixes this by loading the polyfill for `Reflect.construct()`
on browsers that do not support ES2015 (including IE 11).

PR Close #41162

PR Close #41184
@gkalpak gkalpak mentioned this pull request Mar 12, 2021
5 tasks
jessicajaniuk pushed a commit that referenced this pull request Mar 12, 2021
…nts but not ES2015 (#41183)

Before #41162, angular.io was broken on IE 11 due to missing a polyfill
for an API (`Reflect.construct()`) needed by the Custom Elements ES5
shim. #41162 tried to fix this by loading the necessary polyfill
(`es.reflect.construct.js`) on browsers that do not support ES2015
modules (including IE 11).

It turns out that the fix in #41162 was itself broken, because the
`es.reflect.consruct.js` script (included directly in the page via a
`<script>` tag) was in CommonJS format (which cannot run in the browser
as is). By chance, this still allowed browsers that supported neither
Custom Elements nor ES2015 modules (such as IE 11) to work correctly as
a side-effect of loading the `@webcomponents/custom-elements` polyfill
after the Custom Elements ES5 shim (`native-shim.js`). However, on the
few browsers that natively support Custom Elements but not ES2015
modules, angular.io would still be broken.

This commit correctly fixes angular.io on all browsers by properly
bundling the polyfills and transpiling to ES5.

Implementation-wise, we use [esbuild][1] for bundling the polyfills (and
converting from CommonJS to a browser-compatible, IIFE-based format) and
[swc][2] for downleveling the code to ES5 (since `esbuild` only supports
ES2015+).

[1]: https://esbuild.github.io/
[2]: https://swc.rs/

PR Close #41183
jessicajaniuk pushed a commit that referenced this pull request Mar 12, 2021
…nts but not ES2015 (#41183)

Before #41162, angular.io was broken on IE 11 due to missing a polyfill
for an API (`Reflect.construct()`) needed by the Custom Elements ES5
shim. #41162 tried to fix this by loading the necessary polyfill
(`es.reflect.construct.js`) on browsers that do not support ES2015
modules (including IE 11).

It turns out that the fix in #41162 was itself broken, because the
`es.reflect.consruct.js` script (included directly in the page via a
`<script>` tag) was in CommonJS format (which cannot run in the browser
as is). By chance, this still allowed browsers that supported neither
Custom Elements nor ES2015 modules (such as IE 11) to work correctly as
a side-effect of loading the `@webcomponents/custom-elements` polyfill
after the Custom Elements ES5 shim (`native-shim.js`). However, on the
few browsers that natively support Custom Elements but not ES2015
modules, angular.io would still be broken.

This commit correctly fixes angular.io on all browsers by properly
bundling the polyfills and transpiling to ES5.

Implementation-wise, we use [esbuild][1] for bundling the polyfills (and
converting from CommonJS to a browser-compatible, IIFE-based format) and
[swc][2] for downleveling the code to ES5 (since `esbuild` only supports
ES2015+).

[1]: https://esbuild.github.io/
[2]: https://swc.rs/

PR Close #41183
@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 Apr 11, 2021
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: major This PR is targeted for the next major release type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants