-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix(plugin-legacy): legacy fallback for dynamic import #3885
Conversation
Hey @nulladdict, we discussed the different approaches with Evan and we think that we can proceed with this PR for the moment. There is a chance we may change the approach later in case we find a way to directly avoid downloading the modern bundle if it is not needed, but it may not end up happening because the percentage of users affected (0.49% currently) will continue to go down. It looks like it is better to have the fallback as a separate script so we avoid having to include the hash of the legacy bundle in the modern bundle. This allows the user to update the targets for the legacy build, without affecting the modern bundle. <script nomodule src="index-legacy.js"></script>
<script type="module">
try {
new Function('u', `return import(u)`);
} catch () {
// inject index-legacy.js
// warning in the console about the dynamic import error
}
</script>
<script type="module" src="index.js"></script> In the modern bundle import('data:text/javascript;base64,Cg=='); So the bundle is downloaded but it errors out without executing Notes about drawbacks
What do you think? |
Ok, sounds good to me. |
- Add a runtime check to fallback to legacy bundle for browsers with ESM but without dynamic import - Stop enabling polyfillDynamicImport option Closes #3469
Looks good to me, thanks a lot for your work and patience to get to this point @nulladdict! |
@patak-js sure no problem! and yeah thanks @nulladdict for putting all the work |
So I reviewed a bit the PR, it it definetly looks like it will cover my use-case! The one thing that could make it even better (for me at least), would be to have a way to opt-out modern bundle (and thus get rid of the drawbacks). In my case, I'm targeting a sandbox environment where I know dynamic import needs to be polyfilled anyways, so I'd like to disabled the modern bundle tag injection and basically just use Systemjs all the time. something like |
Thanks for reviewing this @AlexandreBonaventure! From your comment, I don't know if you had the opportunity to test the PR in your project, let us know if that is the case because it is very useful feedback. About your proposed |
ok let me try in my project now then |
@knightly-bot build this |
🌒 Knightly build enabled, release every night at 00:00 UTC (skip if no change) |
OK @patak-js I can confirm it works perfectly with our project. Great job all ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
We should notify community to try the next beta
One already confirmed: #3885 (comment), but we should await feedback from more community members with various setups
This only affects plugin-legacy, so we dont need to wait for the next core beta. We could release this in a minor for the plugin |
Ah you are right 🙂 |
Closes #3469
Implementation checklist:
fallbackToLegacyIfNoDynamicImport
(disabled by default)Investigate if it's possible to filter out syntax error from the modern bundle. (We don't want users or tools like Sentry to see this)Even if it's possible, there's no sure way to distinguish betweenimport()
syntax error and a regularSyntaxError
, and we don't want to miss the laterDescription
This is my attempt (or rather PoC) to implement the feature described in #3469.
I'm not quite happy with the current solution, but it's the best I could think of for now.
The problem is that I wanted for the dynamic fallback check to only influence the legacy bundle and not the main one, so proposed solution (check then load correct bundle) wouldn't work, since it requires code execution before even starting to download the correct bundle, while module/nomodule thing works at parse-time.
To not slow down the main bundle, I opted for this approach:
The downsides are that main bundle would error-out if dynamic import syntax is not supported, which would produce error, which is not really desirable. Another potential problem is if the main bundle had no dynamic imports, it would fully execute and legacy bundle would load another copy of the app, which sounds like really bad news
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).