Skip to content

Commit 158d397

Browse files
devmgnclaude
andcommitted
feat(test): enable React Compiler in vitest
Run `babel-plugin-react-compiler` through `@rolldown/plugin-babel` + `reactCompilerPreset` so the memoize behavior in unit tests matches production (Next.js). Keeps hooks and components free of manual `useCallback` / `useMemo` while still catching regressions in tests. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent e87be62 commit 158d397

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
"zod": "4.3.6"
4646
},
4747
"devDependencies": {
48+
"@babel/core": "7.29.0",
4849
"@faker-js/faker": "10.4.0",
4950
"@next/env": "16.2.4",
51+
"@rolldown/plugin-babel": "0.2.3",
5052
"@storybook/addon-a11y": "10.3.5",
5153
"@storybook/addon-docs": "10.3.5",
5254
"@storybook/addon-mcp": "0.6.0",
@@ -57,6 +59,7 @@
5759
"@testing-library/jest-dom": "6.9.1",
5860
"@testing-library/react": "16.3.2",
5961
"@testing-library/user-event": "14.6.1",
62+
"@types/babel__core": "7.20.5",
6063
"@types/node": "24.12.2",
6164
"@types/react": "19.2.14",
6265
"@types/react-dom": "19.2.3",

pnpm-lock.yaml

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

vitest.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import babel from "@rolldown/plugin-babel";
12
import { storybookTest } from "@storybook/addon-vitest/vitest-plugin";
2-
import react from "@vitejs/plugin-react";
3+
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
34
import { playwright } from "@vitest/browser-playwright";
45
import { defineConfig } from "vitest/config";
56

@@ -26,7 +27,12 @@ export default defineConfig({
2627
projects: [
2728
{
2829
extends: true,
29-
plugins: [react()],
30+
plugins: [
31+
react(),
32+
// 本番 (Next.js) と同じ memoize 挙動をテストでも担保するため React Compiler を有効化する。
33+
// @see https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md#react-compiler
34+
babel({ presets: [reactCompilerPreset()] }),
35+
],
3036
test: {
3137
name: "unit",
3238
globals: true,

0 commit comments

Comments
 (0)