Skip to content

Comments

fix(worker): throw error when circular worker import is detected and support self referencing worker#16103

Merged
sapphi-red merged 3 commits intovitejs:mainfrom
sapphi-red:fix/circular-worker-bundle
Mar 6, 2024
Merged

fix(worker): throw error when circular worker import is detected and support self referencing worker#16103
sapphi-red merged 3 commits intovitejs:mainfrom
sapphi-red:fix/circular-worker-bundle

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Mar 6, 2024

Description

The first commit makes Vite to throw an error when a circular worker import is detected.
The second and third commits adds support for simple circular import cases (self reference).

fixes #7015

I didn't add support for complex cases (e.g. worker-a.js has import 'worker-b.js?worker' and worker-b.js has import 'worker-a.js?worker'). For those cases, Vite now throw errors (before this PR, the build never finished). But I think it's fine because doing that is not popular and will make the code complex. I checked that supporting the simple cases makes the build of #7015, #7015 (comment), #12755, #14499, #15288, #15426, jamsinclair/jSquash#15 pass.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines, especially the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels Mar 6, 2024
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added the inconsistency Inconsistency between dev & build label Mar 6, 2024
@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

@patak-dev
Copy link
Member

Awesome! Feel free to merge this one if you'd like to see it in a patch. If not, I'll wait for 5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: web workers inconsistency Inconsistency between dev & build p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing a file from a web worker that imports said web worker causes Vite to build forever

2 participants