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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker): prevent inject esm in classic workers #14918

Merged
merged 1 commit into from Nov 9, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Nov 9, 2023

Description

fix #11266
supersedes #12995

importAnalysis could run on classic worker code, which I think is the only non-ESM code we allow to be processed (?). This PR checks for classic workers and avoid adding top-level imports.

This should also fix the confusing errors from #5396 (does not fix the issue)

Additional context

The fix isn't really clean. I can't think of a way to inline __vite__injectQuery without a significant refactoring.

The test is also subpar but it somewhat works 馃槵


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.

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels Nov 9, 2023
@bluwy bluwy mentioned this pull request Nov 9, 2023
9 tasks
@patak-dev patak-dev merged commit 2687dbb into main Nov 9, 2023
10 checks passed
@patak-dev patak-dev deleted the fix-classic-worker-esm branch November 9, 2023 09:33
@bamtheboozle
Copy link

how exactly do we import a module as a "classic worker" and avoid vite injectquery?

@bluwy
Copy link
Member Author

bluwy commented Nov 13, 2023

For classic workers, you can't use import in dev. You need to use importScripts instead. For imports to work in dev ootb, you can follow #10697

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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected content if there's import() in a js file and import with ?url
3 participants