-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(legacy): ensure isLegacyBundle
checks all entry chunks for legacy suffix
#19858
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
base: main
Are you sure you want to change the base?
Conversation
isLegacyBundle
checks all entry chunks for legacy suffix
How does this happen? plugin-legacy sets
Would you elaborate on this sentence? |
https://bolt.new/~/vitejs-vite-4wh9epy3 |
Does that work? It seems the |
Many tests in legacy.spec.ts are failing. The original implementation considered a bundle to be a legacy bundle if it had one entry chunk marked as legacy. The original implementation has a problem: if there are two entry chunks, where the first is not legacy but the second one is legacy, the function should return true instead of false. |
I was thinking of the following code when I said "Maybe the fix should be changing .find into .all?": Object.values(bundle).every((output) =>
output.type === 'chunk' && output.isEntry ? output.fileName.includes('-legacy') : true,
) This is because I expect all entry chunks that are generated in the legacy bundle to have
I'm not saying your change is incorrect. I'm trying to understand why the change is needed. |
Okay, So next, I'm just going to fix these failed tests? |
Would you explain this first? I'm not quite sure what this PR is fixing. |
Before the modification, the polyfill wasn't generated and systemJs wasn't included, which resulted in the error "system is not defined". After the modification, the polyfill is included, so the "system is not defined" error no longer appears. |
My understanding of your reproduction is:
But |
fix(plugin-legacy): ensure isLegacyBundle checks all entry chunks for legacy suffix
The previous implementation of
isLegacyBundle
found the first entry chunk and then checked if it had a '-legacy' suffix. This could lead to incorrect detection in multi-entry scenarios.For example:
If a bundle contains:
The original implementation would return
false
because it would find "other.js" first and check if it includes "-legacy", which it doesn't.With this fix, the function directly searches for any entry chunk that has the "-legacy" suffix, correctly identifying bundles with any legacy entry chunks.
This ensures proper asset handling in the
generateBundle
hook, especially for multi-entry builds where some entries might be legacy and others modern.