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

Add rollup import transform #6090

Merged
merged 4 commits into from Feb 28, 2024
Merged

Add rollup import transform #6090

merged 4 commits into from Feb 28, 2024

Conversation

marklundin
Copy link
Member

@marklundin marklundin commented Feb 26, 2024

This PR addresses a long standing issue with the UMD build not running on devices without dynamic import() support. See #6011.

This issue stemmed from the use of dynamic import() statement, where import is a reserved keyword and would throw a SyntaxError during parsing on older browsers, even if the code path was never executed.

This PR adds a rollup transform to the UMD build only, which wraps import() statements in a dynamic function. This is only evaluated at runtime, thereby avoiding the parsing on load error. Note that this does not polyfill dynamic imports, it will simply prevent parsing errors on browser without support.

Caveats

This does put a limitation on CSP for UMD builds, however this only applies if all of the following conditions are met

  1. The UMD build is used (not applicable to the ES6 build) AND
  2. Hosting blocks unsafe-eval in their CSP AND
  3. When using either WebGPU or importing an ESM ScriptType

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

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

Looks great, but please give some time for additional opinions before merging.

@kungfooman perhaps?

Copy link
Collaborator

@kungfooman kungfooman left a comment

Choose a reason for hiding this comment

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

Looks very good 👍

utils/rollup-dynamic-import-transform.mjs Outdated Show resolved Hide resolved
marklundin and others added 2 commits February 28, 2024 09:15
@marklundin marklundin merged commit 1d3e127 into main Feb 28, 2024
7 checks passed
@marklundin marklundin deleted the umd-import-transform branch February 28, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants