From 120ab4b8f065482fdfc7a8630ea1ffbe729d301f Mon Sep 17 00:00:00 2001 From: Yarn Date: Thu, 23 Oct 2025 16:07:56 +0200 Subject: [PATCH 1/2] fix(plugin-swc): use SWC when `useAtYourOwnRisk_mutateSwcOptions` is provided When `useAtYourOwnRisk_mutateSwcOptions` is provided, Vite's React SWC plugin should opt into the SWC code path, rather than using esbuild. The current workaround when changing SWC options while not specifying SWC plugins is to provide an empty `plugins` array. Example use-case: preserving comments in the output. --- packages/plugin-react-swc/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-react-swc/src/index.ts b/packages/plugin-react-swc/src/index.ts index 242501818..0a83a3292 100644 --- a/packages/plugin-react-swc/src/index.ts +++ b/packages/plugin-react-swc/src/index.ts @@ -198,7 +198,7 @@ const react = (_options?: Options): Plugin[] => { return { code: newCode ?? result.code, map: result.map } }, }, - options.plugins + options.plugins || options.useAtYourOwnRisk_mutateSwcOptions ? { name: 'vite:react-swc', apply: 'build', From 59fb52fc0f511da90e55d241a8624f874baa2cb7 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 24 Oct 2025 17:49:47 +0900 Subject: [PATCH 2/2] chore: add changelog --- packages/plugin-react-swc/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/plugin-react-swc/CHANGELOG.md b/packages/plugin-react-swc/CHANGELOG.md index bf3196030..a74bdcbb6 100644 --- a/packages/plugin-react-swc/CHANGELOG.md +++ b/packages/plugin-react-swc/CHANGELOG.md @@ -6,6 +6,10 @@ SSR applications can now initialize HMR runtime by importing `@vitejs/plugin-react-swc/preamble` at the top of their client entry instead of manually calling `transformIndexHtml`. This simplifies SSR setup for applications that don't use the `transformIndexHtml` API. +### Use SWC when useAtYourOwnRisk_mutateSwcOptions is provided ([#951](https://github.com/vitejs/vite-plugin-react/pull/951)) + +Previously, this plugin did not use SWC if plugins were not provided even if `useAtYourOwnRisk_mutateSwcOptions` was provided. This is now fixed. + ## 4.1.0 (2025-09-17) ### Set SWC cacheRoot options