Skip to content

Commit

Permalink
fix(plugin-react): check for import React statement in .js files (#6320)
Browse files Browse the repository at this point in the history
* fix: reactPlugin skip inject react hmr code to workerFile (fix #6148)

* Revert "fix: reactPlugin skip inject react hmr code to workerFile (fix #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 4, 2022
1 parent 26512de commit bd9e97b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugin-react/src/index.ts
Expand Up @@ -118,7 +118,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 || importReactRE.test(code)
if (isReactModule && filter(id)) {
useFastRefresh = true
plugins.push([
Expand Down

0 comments on commit bd9e97b

Please sign in to comment.