Skip to content

Commit

Permalink
fix(plugin-react): check for import React statement in .js files (vit…
Browse files Browse the repository at this point in the history
…ejs#6320)

* fix: reactPlugin skip inject react hmr code to workerFile (fix vitejs#6148)

* Revert "fix: reactPlugin skip inject react hmr code to workerFile (fix vitejs#6148)"

This reverts commit 136883d.

* fix(plugin-react): check for import React statement in .js files

…instead of using naïve `code.includes("react")` check

Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com>
  • Loading branch information
toSayNothing and aleclarson committed Jan 6, 2022
1 parent 297937e commit 390b778
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,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 = id.endsWith('x') || code.includes('react')
const isReactModule = id.endsWith('x') || importReactRE.test(code)
if (isReactModule && filter(id)) {
useFastRefresh = true
plugins.push([
Expand Down

0 comments on commit 390b778

Please sign in to comment.