@vitejs/plugin-react 4.3.2 → 4.3.3

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
@@ -198,7 +198,7 @@ function viteReact(opts = {}) {
198
198
  // Required for esbuild.jsxDev to provide correct line numbers
199
199
  // This crates issues the react compiler because the re-order is too important
200
200
  // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
201
- retainLines: hasCompiler(plugins) ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
201
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
202
202
  parserOpts: {
203
203
  ...babelOptions.parserOpts,
204
204
  sourceType: "module",
@@ -225,10 +225,17 @@ function viteReact(opts = {}) {
225
225
  }
226
226
  }
227
227
  };
228
- const dependencies = ["react", jsxImportDevRuntime, jsxImportRuntime];
228
+ const dependencies = [
229
+ "react",
230
+ "react-dom",
231
+ jsxImportDevRuntime,
232
+ jsxImportRuntime
233
+ ];
229
234
  const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
230
- if (hasCompilerWithDefaultRuntime(staticBabelPlugins)) {
231
- dependencies.push("react/compiler-runtime");
235
+ const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
236
+ if (reactCompilerPlugin != null) {
237
+ const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
238
+ dependencies.push(reactCompilerRuntimeModule);
232
239
  }
233
240
  const viteReactRefresh = {
234
241
  name: "vite:react-refresh",
@@ -313,15 +320,21 @@ function createBabelOptions(rawOptions) {
313
320
  function defined(value) {
314
321
  return value !== void 0;
315
322
  }
316
- function hasCompiler(plugins) {
317
- return plugins.some(
323
+ function getReactCompilerPlugin(plugins) {
324
+ return plugins.find(
318
325
  (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler"
319
326
  );
320
327
  }
321
- function hasCompilerWithDefaultRuntime(plugins) {
322
- return plugins.some(
323
- (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler" && p[1]?.runtimeModule === void 0
324
- );
328
+ function getReactCompilerRuntimeModule(plugin) {
329
+ let moduleName = "react/compiler-runtime";
330
+ if (Array.isArray(plugin)) {
331
+ if (plugin[1]?.target === "17" || plugin[1]?.target === "18") {
332
+ moduleName = "react-compiler-runtime";
333
+ } else if (typeof plugin[1]?.runtimeModule === "string") {
334
+ moduleName = plugin[1]?.runtimeModule;
335
+ }
336
+ }
337
+ return moduleName;
325
338
  }
326
339
 
327
340
  module.exports = viteReact;
package/dist/index.mjs CHANGED
@@ -190,7 +190,7 @@ function viteReact(opts = {}) {
190
190
  // Required for esbuild.jsxDev to provide correct line numbers
191
191
  // This crates issues the react compiler because the re-order is too important
192
192
  // People should use @babel/plugin-transform-react-jsx-development to get back good line numbers
193
- retainLines: hasCompiler(plugins) ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
193
+ retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
194
194
  parserOpts: {
195
195
  ...babelOptions.parserOpts,
196
196
  sourceType: "module",
@@ -217,10 +217,17 @@ function viteReact(opts = {}) {
217
217
  }
218
218
  }
219
219
  };
220
- const dependencies = ["react", jsxImportDevRuntime, jsxImportRuntime];
220
+ const dependencies = [
221
+ "react",
222
+ "react-dom",
223
+ jsxImportDevRuntime,
224
+ jsxImportRuntime
225
+ ];
221
226
  const staticBabelPlugins = typeof opts.babel === "object" ? opts.babel?.plugins ?? [] : [];
222
- if (hasCompilerWithDefaultRuntime(staticBabelPlugins)) {
223
- dependencies.push("react/compiler-runtime");
227
+ const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
228
+ if (reactCompilerPlugin != null) {
229
+ const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
230
+ dependencies.push(reactCompilerRuntimeModule);
224
231
  }
225
232
  const viteReactRefresh = {
226
233
  name: "vite:react-refresh",
@@ -305,15 +312,21 @@ function createBabelOptions(rawOptions) {
305
312
  function defined(value) {
306
313
  return value !== void 0;
307
314
  }
308
- function hasCompiler(plugins) {
309
- return plugins.some(
315
+ function getReactCompilerPlugin(plugins) {
316
+ return plugins.find(
310
317
  (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler"
311
318
  );
312
319
  }
313
- function hasCompilerWithDefaultRuntime(plugins) {
314
- return plugins.some(
315
- (p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler" && p[1]?.runtimeModule === void 0
316
- );
320
+ function getReactCompilerRuntimeModule(plugin) {
321
+ let moduleName = "react/compiler-runtime";
322
+ if (Array.isArray(plugin)) {
323
+ if (plugin[1]?.target === "17" || plugin[1]?.target === "18") {
324
+ moduleName = "react-compiler-runtime";
325
+ } else if (typeof plugin[1]?.runtimeModule === "string") {
326
+ moduleName = plugin[1]?.runtimeModule;
327
+ }
328
+ }
329
+ return moduleName;
317
330
  }
318
331
 
319
332
  export { viteReact as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "4.3.2",
3
+ "version": "4.3.3",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "contributors": [