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

fix(plugin-legacy): fix legacy plugin not working in worker context #19079

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sapenlei
Copy link
Contributor

closes #19073

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

I don't think this is correct. The worker entry chunks are not legacy chunks.

@sapphi-red sapphi-red added plugin: legacy p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels Dec 27, 2024
@sapenlei
Copy link
Contributor Author

I don't think this is correct. The worker entry chunks are not legacy chunks.

Okay, I'll change it.

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

I guess this change will make the built application error in runtime because the legacy plugin does not transpile the worker content. I think we need to

  1. show an warning if a worker is used when legacy chunks are generated
  2. [optional] avoid injecting __vite_legacy_guard to worker chunks so that workers work in that case

The ideal fix is to generate legacy chunks for workers. But that's hard to do.

@sapenlei
Copy link
Contributor Author

sapenlei commented Jan 7, 2025

CleanShot 2025-01-07 at 16 25 31@2x
It's because when iife format,esbuild doesn't convert, I think I changed it correctly and tested it locally with no problems! 😭 @sapphi-red

@sapenlei
Copy link
Contributor Author

sapenlei commented Jan 7, 2025

CleanShot 2025-01-07 at 16 31 21@2x
So when it's a worker and it's in iife format, esbuild converts the iife

@sapphi-red
Copy link
Member

sapphi-red commented Jan 8, 2025

I guess this PR would make esbuild to transform export function __vite_legacy_guard() into a different syntax. But that code is there to avoid running the modern chunk in legacy browsers. If that code is transformed to a different code, the modern chunk (which is not transformed for legacy browsers and contains modern syntaxes) will be loaded in legacy browsers and will error.

I haven't tested, but this reproduction probably won't work on Chrome 45 because dist/assets/worker-C_luD0Fa.js contains spread syntax as-is.
https://stackblitz.com/edit/vitejs-vite-5f1azdhv?file=vite.config.js&terminal=build

@sapphi-red
Copy link
Member

Oh, I noticed that the reproduction of #19073 is passing plugin-legacy to worker.plugins.
I think we should output a warning here by checking config.isWorker in this case.

configResolved(config) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority) plugin: legacy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to package normal files in web worker
2 participants