Skip to content

Conversation

@ihch
Copy link
Contributor

@ihch ihch commented Oct 20, 2023

Description

Fix: #14435

In the same way as #11919, change to use shouldTransformCachedModule to re-transform workerImportMetaUrl when in build watch mode.

In build watch mode, the transform hook will not be called after the load hook of vite:worker plugin except in the very first build. So use shouldtransformcachedmodule hook to indicate re-call transform hook in watch build mode.

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.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • 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).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bolt-new-by-stackblitz
Copy link

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

Comment on lines 113 to 122
const isIncludeWorkerImportMetaUrl = (code: string): boolean => {
if (
(code.includes('new Worker') || code.includes('new SharedWorker')) &&
code.includes('new URL') &&
code.includes(`import.meta.url`)
) {
return true
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

Since this function isn't using any variables in workerImportMetaUrlPlugin, I think we can move this out and above the workerImportMetaUrlPlugin plugin as a normal function isIncludeWorkerImportMetaUrl(code: string).

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels Oct 25, 2023
@ihch ihch requested a review from bluwy October 27, 2023 12:04
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Thanks!

@bluwy bluwy merged commit 8db40ee into vitejs:main Oct 30, 2023
@ihch ihch deleted the fix/build-watch-worker-import-meta-url branch November 7, 2023 10:14
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.

build --watch doesnt build workers (new Worker(new URL()))

2 participants