Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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) {

@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) and removed p3-minor-bug An edge case that only affects very specific usage (priority) labels Feb 4, 2025
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.

Thanks

@sapphi-red sapphi-red changed the title fix(plugin-legacy): fix legacy plugin not working in worker context fix(plugin-legacy): warn if plugin-legacy is passed to worker.plugins Feb 7, 2025
@sapphi-red sapphi-red changed the title fix(plugin-legacy): warn if plugin-legacy is passed to worker.plugins fix(legacy): warn if plugin-legacy is passed to worker.plugins Feb 7, 2025
@sapphi-red sapphi-red merged commit 171f2fb into vitejs:main Feb 7, 2025
17 checks passed
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: web workers p2-edge-case Bug, but has workaround or limited in scope (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