@vitejs/plugin-react 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -49,10 +49,11 @@ window.__vite_plugin_react_preamble_installed__ = true
49
49
  const header = `
50
50
  import RefreshRuntime from "${runtimePublicPath}";
51
51
 
52
+ const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
52
53
  let prevRefreshReg;
53
54
  let prevRefreshSig;
54
55
 
55
- if (import.meta.hot) {
56
+ if (import.meta.hot && !inWebWorker) {
56
57
  if (!window.__vite_plugin_react_preamble_installed__) {
57
58
  throw new Error(
58
59
  "@vitejs/plugin-react can't detect preamble. Something is wrong. " +
@@ -68,7 +69,7 @@ if (import.meta.hot) {
68
69
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
69
70
  }`.replace(/\n+/g, "");
70
71
  const footer = `
71
- if (import.meta.hot) {
72
+ if (import.meta.hot && !inWebWorker) {
72
73
  window.$RefreshReg$ = prevRefreshReg;
73
74
  window.$RefreshSig$ = prevRefreshSig;
74
75
 
@@ -121,7 +122,7 @@ function viteReact(opts = {}) {
121
122
  devBase = config.base;
122
123
  projectRoot = config.root;
123
124
  isProduction = config.isProduction;
124
- skipFastRefresh = isProduction || config.command === "build";
125
+ skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
125
126
  if ("jsxPure" in opts) {
126
127
  config.logger.warnOnce(
127
128
  "[@vitejs/plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly."
@@ -154,7 +155,7 @@ function viteReact(opts = {}) {
154
155
  })();
155
156
  const plugins = [...babelOptions.plugins];
156
157
  const isJSX = filepath.endsWith("x");
157
- const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? code.includes(devRuntime) : importReactRE.test(code)));
158
+ const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(devRuntime)));
158
159
  if (useFastRefresh) {
159
160
  plugins.push([
160
161
  await loadPlugin("react-refresh/babel"),
package/dist/index.mjs CHANGED
@@ -29,10 +29,11 @@ window.__vite_plugin_react_preamble_installed__ = true
29
29
  const header = `
30
30
  import RefreshRuntime from "${runtimePublicPath}";
31
31
 
32
+ const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
32
33
  let prevRefreshReg;
33
34
  let prevRefreshSig;
34
35
 
35
- if (import.meta.hot) {
36
+ if (import.meta.hot && !inWebWorker) {
36
37
  if (!window.__vite_plugin_react_preamble_installed__) {
37
38
  throw new Error(
38
39
  "@vitejs/plugin-react can't detect preamble. Something is wrong. " +
@@ -48,7 +49,7 @@ if (import.meta.hot) {
48
49
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
49
50
  }`.replace(/\n+/g, "");
50
51
  const footer = `
51
- if (import.meta.hot) {
52
+ if (import.meta.hot && !inWebWorker) {
52
53
  window.$RefreshReg$ = prevRefreshReg;
53
54
  window.$RefreshSig$ = prevRefreshSig;
54
55
 
@@ -101,7 +102,7 @@ function viteReact(opts = {}) {
101
102
  devBase = config.base;
102
103
  projectRoot = config.root;
103
104
  isProduction = config.isProduction;
104
- skipFastRefresh = isProduction || config.command === "build";
105
+ skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
105
106
  if ("jsxPure" in opts) {
106
107
  config.logger.warnOnce(
107
108
  "[@vitejs/plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly."
@@ -134,7 +135,7 @@ function viteReact(opts = {}) {
134
135
  })();
135
136
  const plugins = [...babelOptions.plugins];
136
137
  const isJSX = filepath.endsWith("x");
137
- const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? code.includes(devRuntime) : importReactRE.test(code)));
138
+ const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(devRuntime)));
138
139
  if (useFastRefresh) {
139
140
  plugins.push([
140
141
  await loadPlugin("react-refresh/babel"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "contributors": [
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
41
41
  "dependencies": {
42
- "@babel/core": "^7.21.4",
43
- "@babel/plugin-transform-react-jsx-self": "^7.21.0",
44
- "@babel/plugin-transform-react-jsx-source": "^7.19.6",
42
+ "@babel/core": "^7.22.5",
43
+ "@babel/plugin-transform-react-jsx-self": "^7.22.5",
44
+ "@babel/plugin-transform-react-jsx-source": "^7.22.5",
45
45
  "react-refresh": "^0.14.0"
46
46
  },
47
47
  "peerDependencies": {