Skip to content

Commit

Permalink
fix: reactPlugin skip inject react hmr code to workerFile (fix vitejs…
Browse files Browse the repository at this point in the history
  • Loading branch information
toSayNothing committed Dec 30, 2021
1 parent a8a0d84 commit 136883d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export default function viteReact(opts: Options = {}): PluginOption[] {

if (/\.(mjs|[tj]sx?)$/.test(extension)) {
const isJSX = extension.endsWith('x')
// as worker, querystring could be
// import MyWorker from './worker?worker' => worker
// import MyWorker from './worker?worker&inline' => worker&inline
// transformed by webWorkerPlugin :'/worker?worker_file' => worker_file
const isWorker = querystring.includes('worker')
const isNodeModules = id.includes('/node_modules/')
const isProjectFile =
!isNodeModules && (id[0] === '\0' || id.startsWith(projectRoot + '/'))
Expand All @@ -118,7 +123,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
let useFastRefresh = false
if (!skipFastRefresh && !ssr && !isNodeModules) {
// Modules with .js or .ts extension must import React.
const isReactModule = isJSX || code.includes('react')
const isReactModule = isJSX || (code.includes('react') && !isWorker)
if (isReactModule && filter(id)) {
useFastRefresh = true
plugins.push([
Expand Down

0 comments on commit 136883d

Please sign in to comment.