Skip to content

Commit 3cfb1d1

Browse files
authored
fix(plugin-react): fix compiler.logDiagnostics (#1483)
1 parent 6de9915 commit 3cfb1d1

6 files changed

Lines changed: 99 additions & 89 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ jobs:
119119
- name: Build
120120
run: pnpm run build
121121

122+
- name: Unit tests
123+
run: pnpm run test-unit
124+
122125
- name: Lint
123126
run: pnpm run lint
124127

‎packages/plugin-react/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fix `compiler.logDiagnostics` option not working ([#1483](https://github.com/vitejs/vite-plugin-react/pull/1483))
6+
7+
With `oxc-transform-react` >= 0.148, the `logDiagnostics` was not working. This version fixes it and requires `oxc-transform-react` >= 0.152 as a peer dependency if you are using the `compiler` option. `compiler.logDiagnostics` option is now deprecated and should be swapped for the builtin `compiler.reportDiagnostics`.
8+
59
### Disable refresh for non-jsx with compiler enabled (fix [#1478](https://github.com/vitejs/vite-plugin-react/issues/1478)) ([#1485](https://github.com/vitejs/vite-plugin-react/pull/1485))
610

711
When the compiler was enabled, TS files could trigger fast refresh which would cause runtime errors. The logic now follows what the builtin oxc plugin in Vite does.

‎packages/plugin-react/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@rolldown/plugin-babel": "^0.2.4",
5050
"@vitejs/react-common": "workspace:*",
5151
"babel-plugin-react-compiler": "^1.0.0",
52-
"oxc-transform-react": "^0.151.0",
52+
"oxc-transform-react": "^0.152.0",
5353
"react": "^19.3.0",
5454
"react-dom": "^19.3.0",
5555
"rolldown": "^1.2.9",
@@ -59,7 +59,7 @@
5959
"peerDependencies": {
6060
"@rolldown/plugin-babel": "^0.1.7 || ^0.2.0",
6161
"babel-plugin-react-compiler": "^1.0.0",
62-
"oxc-transform-react": "^0.145.0",
62+
"oxc-transform-react": "^0.152.0",
6363
"vite": "^8.0.0"
6464
},
6565
"peerDependenciesMeta": {

‎packages/plugin-react/src/index.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface ReactCompilerPluginOptions extends ReactCompilerOptions {
2525
* Log recoverable React Compiler diagnostics through Vite.
2626
* Fatal diagnostics are always logged and fail the transform.
2727
* @default false
28+
* @deprecated Use `reportDiagnostics` instead
2829
*/
2930
logDiagnostics?: boolean
3031
}
@@ -378,7 +379,11 @@ function createReactCompilerPlugin(
378379
importSource: reactOptions.jsxImportSource,
379380
refresh: refreshEnabled,
380381
},
381-
reactCompiler: shouldCompile ? reactCompilerOptions : false,
382+
reactCompiler: !shouldCompile
383+
? false
384+
: logDiagnostics
385+
? { ...reactCompilerOptions, reportDiagnostics: true }
386+
: reactCompilerOptions,
382387
sourcemap: this.environment
383388
? this.environment.config.command !== 'build' ||
384389
!!this.environment.config.build.sourcemap
@@ -394,10 +399,8 @@ function createReactCompilerPlugin(
394399
diagnostics.join('\n\n') || 'React Compiler transform failed.',
395400
)
396401
}
397-
if (logDiagnostics) {
398-
for (const diagnostic of diagnostics) {
399-
this.warn(diagnostic)
400-
}
402+
for (const diagnostic of diagnostics) {
403+
this.warn(diagnostic)
401404
}
402405

403406
return { code: result.code, map: result.map }

‎packages/plugin-react/tests/reactCompiler.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('compiler option', () => {
144144
const diagnostics: unknown[] = []
145145

146146
await transformWithBuildConfig(
147-
{ logDiagnostics: true },
147+
{ reportDiagnostics: true },
148148
{},
149149
'client',
150150
`

‎pnpm-lock.yaml‎

Lines changed: 81 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)