@vitejs/plugin-react 6.1.0 → 6.1.1

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/README.md CHANGED
@@ -106,6 +106,12 @@ The `compiler` option also accepts [React Compiler options](https://react.dev/re
106
106
  react({ compiler: { compilationMode: 'annotation' } })
107
107
  ```
108
108
 
109
+ Set `logDiagnostics` to `true` to log recoverable React Compiler diagnostics through Vite. This option defaults to `false`. Fatal diagnostics are always logged and fail the transform.
110
+
111
+ ```js
112
+ react({ compiler: { logDiagnostics: true } })
113
+ ```
114
+
109
115
  ### Babel React Compiler
110
116
 
111
117
  React Compiler can also be used through Babel with the exported `reactCompilerPreset` helper. This requires [`@rolldown/plugin-babel`](https://npmx.dev/package/@rolldown/plugin-babel), [`babel-plugin-react-compiler`](https://npmx.dev/package/babel-plugin-react-compiler), and [`@babel/core`](https://npmx.dev/package/@babel/core) as peer dependencies:
package/dist/index.d.ts CHANGED
@@ -4,6 +4,14 @@ import { ReactCompilerBabelPluginOptions, ReactCompilerOptions, RolldownBabelPre
4
4
  declare const reactCompilerPreset: (options?: ReactCompilerBabelPluginOptions) => RolldownBabelPreset;
5
5
  //#endregion
6
6
  //#region src/index.d.ts
7
+ interface ReactCompilerPluginOptions extends ReactCompilerOptions {
8
+ /**
9
+ * Log recoverable React Compiler diagnostics through Vite.
10
+ * Fatal diagnostics are always logged and fail the transform.
11
+ * @default false
12
+ */
13
+ logDiagnostics?: boolean;
14
+ }
7
15
  interface Options {
8
16
  /**
9
17
  * Can be used to process extra files like `.mdx`
@@ -43,7 +51,7 @@ interface Options {
43
51
  * @default false
44
52
  * @experimental
45
53
  */
46
- compiler?: boolean | ReactCompilerOptions;
54
+ compiler?: boolean | ReactCompilerPluginOptions;
47
55
  }
48
56
  declare function viteReact(opts?: Options): Plugin[];
49
57
  declare namespace viteReact {
@@ -51,4 +59,4 @@ declare namespace viteReact {
51
59
  }
52
60
  declare function viteReactForCjs(this: unknown, options: Options): Plugin[];
53
61
  //#endregion
54
- export { Options, type ReactCompilerOptions, viteReact as default, viteReactForCjs as "module.exports", reactCompilerPreset };
62
+ export { Options, type ReactCompilerPluginOptions as ReactCompilerOptions, viteReact as default, viteReactForCjs as "module.exports", reactCompilerPreset };
package/dist/index.js CHANGED
@@ -194,11 +194,10 @@ function viteReact(opts = {}) {
194
194
  if (opts.compiler) plugins.unshift(createReactCompilerPlugin(opts.compiler === true ? {} : opts.compiler, include, exclude, opts, () => !skipFastRefresh));
195
195
  return plugins;
196
196
  }
197
- function createReactCompilerPlugin(options, include, exclude, reactOptions, isFastRefreshEnabled) {
198
- let sourcemap = true;
197
+ function createReactCompilerPlugin({ logDiagnostics, ...reactCompilerOptions }, include, exclude, reactOptions, isFastRefreshEnabled) {
199
198
  let jsxDevelopment = false;
200
199
  let compiler;
201
- const runtime = options.target === "17" || options.target === "18" ? "react-compiler-runtime" : "react/compiler-runtime";
200
+ const runtime = reactCompilerOptions.target === "17" || reactCompilerOptions.target === "18" ? "react-compiler-runtime" : "react/compiler-runtime";
202
201
  const loadCompiler = async (onError) => {
203
202
  if (compiler) return compiler;
204
203
  try {
@@ -215,7 +214,6 @@ function createReactCompilerPlugin(options, include, exclude, reactOptions, isFa
215
214
  return { optimizeDeps: { include: [runtime] } };
216
215
  },
217
216
  configResolved(config) {
218
- sourcemap = config.command !== "build" || !!config.build.sourcemap;
219
217
  jsxDevelopment = !config.isProduction;
220
218
  },
221
219
  transform: {
@@ -225,7 +223,7 @@ function createReactCompilerPlugin(options, include, exclude, reactOptions, isFa
225
223
  } },
226
224
  async handler(code, id) {
227
225
  const isClient = this.environment?.config.consumer !== "server";
228
- const shouldCompile = isClient && (options.compilationMode === "annotation" ? /['"]use memo['"]/.test(code) : defaultCodeFilter.test(code));
226
+ const shouldCompile = isClient && (reactCompilerOptions.compilationMode === "annotation" ? /['"]use memo['"]/.test(code) : defaultCodeFilter.test(code));
229
227
  const { transform } = compiler ?? await loadCompiler((message) => this.error(message));
230
228
  const result = await transform(id.split("?")[0], code, {
231
229
  jsx: {
@@ -234,12 +232,12 @@ function createReactCompilerPlugin(options, include, exclude, reactOptions, isFa
234
232
  importSource: reactOptions.jsxImportSource,
235
233
  refresh: isClient && isFastRefreshEnabled()
236
234
  },
237
- reactCompiler: shouldCompile ? options : false,
238
- sourcemap
235
+ reactCompiler: shouldCompile ? reactCompilerOptions : false,
236
+ sourcemap: this.environment ? this.environment.config.command !== "build" || !!this.environment.config.build.sourcemap : true
239
237
  });
240
238
  const diagnostics = result.errors.map((error) => `${error.message}${error.codeframe ? `\n${error.codeframe}` : ""}`);
241
239
  if (result.fatal) this.error(diagnostics.join("\n\n") || "React Compiler transform failed.");
242
- for (const diagnostic of diagnostics) this.warn(diagnostic);
240
+ if (logDiagnostics) for (const diagnostic of diagnostics) this.warn(diagnostic);
243
241
  return {
244
242
  code: result.code,
245
243
  map: result.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
4
4
  "description": "The default Vite plugin for React projects",
5
5
  "keywords": [
6
6
  "fast refresh",
@@ -50,12 +50,12 @@
50
50
  "@rolldown/plugin-babel": "^0.2.3",
51
51
  "@vitejs/react-common": "workspace:*",
52
52
  "babel-plugin-react-compiler": "^1.0.0",
53
- "oxc-transform-react": "^0.145.0",
53
+ "oxc-transform-react": "^0.147.0",
54
54
  "react": "^19.2.8",
55
55
  "react-dom": "^19.2.8",
56
- "rolldown": "^1.2.3",
56
+ "rolldown": "^1.2.6",
57
57
  "tsdown": "^0.22.14",
58
- "vite": "^8.2.1"
58
+ "vite": "^8.2.2"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@rolldown/plugin-babel": "^0.1.7 || ^0.2.0",