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

Polyfill does not run as expected #430

Open
benj-p opened this issue May 28, 2024 · 4 comments
Open

Polyfill does not run as expected #430

benj-p opened this issue May 28, 2024 · 4 comments

Comments

@benj-p
Copy link

benj-p commented May 28, 2024

I have a Rails (7.1.3) app with importmap-rails (2.0.1). We noticed that when visiting the website with the Random User-Agent (Switcher) Chrome extension we get these error messages in the console and importmap does not work.

image

I would have expected the polyfill to run but it doesn't seem to be the case here. This is what I have in the head of my page

    %script{ async: true, src: "https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js", "data-turbo-track": "reload" }
    = javascript_importmap_tags
    = javascript_import_module_tag 'controllers'

Any guidance would be greatly appreciated 🙏

@guybedford
Copy link
Owner

Import maps are supported natively in modern Chrome - so the polyfill will not apply if you are only relying on a feature like import maps that is already supported.

Instead, this is a bug with the code against the native implementation of import maps - that import maps must be loaded before any modules execute on the page and cannot be loaded after a single module has been loaded. Try carefully inspecting your HTML to ensure all module loads come after the import map.

@benj-p
Copy link
Author

benj-p commented May 29, 2024

Thanks for the prompt answer @guybedford.

The page has no error and works as expected when browsed without the Random User-Agent (Switcher) Chrome extension. When the extension in enabled though, I get those error messages. I have inspected my HTML however and in both cases, whether the extension is enabled or disabled, I can confirm that there are no module loads before the import map - which is odd given the error message I'm seeing.

But what I understand from your reply is that the polyfill will not apply in Chrome, so I guess this issue is not related to es-module-shims. If that's correct I will close this issue and create one issue with importmap-rails instead.

@guybedford
Copy link
Owner

@benj-p you may find that the root cause here is WICG/import-maps#248. Unfortunately it's a bit of a gotcha, and is best treated as an "extension issue" actually currently.

@benj-p
Copy link
Author

benj-p commented Jun 6, 2024

Thanks, I had indeed found this issue and I came here to post an issue following your comment ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants