-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Include the shim as defer
instead of async
#385
Comments
While Note that if you do This then also ensures that the import maps polyfill being loaded doesn't block code exection when it isn't needed as well. If you really need to check for and use the |
@guybedford I have oversimplified the example a bit, apologies. So do I understand correctly that I don't actually need to use importShim(...) for dynamic imports since as long as the module fails on a static import and gets polyfilled, plain import(...) will also work? I may have misunderstood that part of README. |
@JanPokorny yes that's correct. |
@guybedford Understood, thanks! In that case I understand that the only need for |
@JanPokorny you're correct, we could update that note to note that doing this means changing to defer for the load order semantics. It's a shame browsers don't have an "async in order" mode. |
Hello! I have found a possible bug when using
importShim
for dynamic imports, that can manifest when the script is included in the recommended way with theasync
attribute.This example (https://jsfiddle.net/tac5oz0v/), adapted from the README:
...fails with
Uncaught ReferenceError: importShim is not defined
when ran in a browser that fully supports modules, and at the same time can executedefer
scripts beforeasync
-- like Firefox 116.0. There is nothing preventing thetype="module"
script from executing before the shim, even though in this case the shim is still needed for theimportShim
function. This does not happen in browsers that can't run the module scripts without the shim (missing support for some feature which is polyfilled after the shim is loaded), since by that point the shim is already loaded by definition.This is a simple example, but the issue can get pretty confusing when combined with a complex codebase with several levels of imports, testing in multiple browsers and better yet having the script inclusion hidden inside a gem (which correctly includes
async
according to the README). And it's non-deterministic by principle, which is fun to debug.I would suggest changing the recommended way of inclusion of the shim from
async
todefer
, which avoids this edge case -- the HTML spec requiresdefer
andtype="module"
scripts to execute in the order of appearance.The text was updated successfully, but these errors were encountered: