A local-first personal finance app
[AI] Enable React Compiler for all monorepo packages with React code (#8463)
Matiss Janis Aboltins0c96d7701b9c
diff --git a/AGENTS.md b/AGENTS.mdindex 2e6c0da0a3..753169f18e 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -286,7 +286,7 @@ wrapping isn't possible).**React Patterns:**-- The project uses **React Compiler** (`babel-plugin-react-compiler`) in the desktop-client. The compiler auto-memoizes component bodies, so you can omit manual `useCallback`, `useMemo`, and `React.memo` when adding or refactoring code; prefer inline callbacks and values unless a stable identity is required by a non-compiled dependency.+- The project uses **React Compiler** (`babel-plugin-react-compiler`) in all app packages with React code (desktop-client, component-library). The compiler auto-memoizes component bodies, so you can omit manual `useCallback`, `useMemo`, and `React.memo` when adding or refactoring code; prefer inline callbacks and values unless a stable identity is required by a non-compiled dependency.- Avoid unstable nested components**JSX Style:**diff --git a/packages/component-library/.storybook/main.ts b/packages/component-library/.storybook/main.tsindex 53dd92cd27..6d3c98585e 100644--- a/packages/component-library/.storybook/main.ts+++ b/packages/component-library/.storybook/main.ts@@ -1,8 +1,14 @@import { dirname } from 'path';import { fileURLToPath } from 'url';+import babel from '@rolldown/plugin-babel';import type { StorybookConfig } from '@storybook/react-vite';-import react from '@vitejs/plugin-react';+import react, { reactCompilerPreset } from '@vitejs/plugin-react';++// Any workspace package's source; node_modules stays excluded by the babel+// plugin's default exclude.+const reactCompilerInclude =+ /[\\/]packages[\\/][^\\/]+[\\/]src[\\/].*\.[jt]sx(?:$|\?)/;/*** This function is used to resolve the absolute path of a package.@@ -32,7 +38,14 @@ const config: StorybookConfig = {const { mergeConfig } = await import('vite');return mergeConfig(config, {- plugins: [react()],+ plugins: [+ react(),+ babel({+ include: [reactCompilerInclude],+ // n.b. Must be a string to ensure plugin resolution order. See https://github.com/actualbudget/actual/pull/5853+ presets: [reactCompilerPreset()],+ }),+ ],resolve: {tsconfigPaths: true,},diff --git a/packages/component-library/package.json b/packages/component-library/package.jsonindex 0677fad66e..86e5f7c444 100644--- a/packages/component-library/package.json+++ b/packages/component-library/package.json@@ -43,8 +43,7 @@},"scripts": {"generate:icons": "rm src/icons/*/*.tsx; cd src/icons && svgr --template template.ts --index-template index-template.ts --typescript --expand-props start -d . .",- "test": "npm-run-all -cp 'test:*'",- "test:web": "ENV=web vitest --run -c vitest.web.config.ts",+ "test": "ENV=web vitest --run -c vitest.web.config.ts","start:storybook": "storybook dev -p 6006","build:storybook": "storybook build","typecheck": "tsgo -b"@@ -56,6 +55,7 @@},"devDependencies": {"@chromatic-com/storybook": "^5.2.1",+ "@rolldown/plugin-babel": "~0.2.3","@storybook/addon-a11y": "^10.4.4","@storybook/addon-docs": "^10.4.4","@storybook/react-vite": "^10.4.4",@@ -66,6 +66,7 @@"@types/react": "^19.2.17","@typescript/native-preview": "beta","@vitejs/plugin-react": "^6.0.2",+ "babel-plugin-react-compiler": "^1.0.0","eslint-plugin-storybook": "^10.4.4","react": "19.2.7","react-dom": "19.2.7",diff --git a/packages/component-library/vitest.web.config.ts b/packages/component-library/vitest.web.config.tsindex 3d701122d2..638c329cd1 100644--- a/packages/component-library/vitest.web.config.ts+++ b/packages/component-library/vitest.web.config.ts@@ -1,6 +1,12 @@-import react from '@vitejs/plugin-react';+import babel from '@rolldown/plugin-babel';+import react, { reactCompilerPreset } from '@vitejs/plugin-react';import { defineConfig } from 'vitest/config';+// Any workspace package's source; node_modules stays excluded by the babel+// plugin's default exclude.+const reactCompilerInclude =+ /[\\/]packages[\\/][^\\/]+[\\/]src[\\/].*\.[jt]sx(?:$|\?)/;+export default defineConfig({test: {environment: 'jsdom',@@ -20,5 +26,12 @@ export default defineConfig({]: ['default'],},- plugins: [react()],+ plugins: [+ react(),+ babel({+ include: [reactCompilerInclude],+ // n.b. Must be a string to ensure plugin resolution order. See https://github.com/actualbudget/actual/pull/5853+ presets: [reactCompilerPreset()],+ }),+ ],});diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mtsindex 974564e62f..f7b20092bd 100644--- a/packages/desktop-client/vite.config.mts+++ b/packages/desktop-client/vite.config.mts@@ -22,8 +22,13 @@ import type { Plugin } from 'vite';import { VitePWA } from 'vite-plugin-pwa';const __dirname = path.dirname(fileURLToPath(import.meta.url));+// Compile every workspace package that ships React components. Workspace+// imports resolve to their real paths under packages/<name>/src, so any+// current or future package flowing through this build is picked up+// automatically. Third-party code is never compiled: the babel plugin's+// default exclude (node_modules) still applies alongside this include.const reactCompilerInclude =- /[\\/]desktop-client[\\/]src[\\/].*\.[jt]sx(?:$|\?)/;+ /[\\/]packages[\\/][^\\/]+[\\/]src[\\/].*\.[jt]sx(?:$|\?)/;const addWatchers = (): Plugin => ({name: 'add-watchers',diff --git a/upcoming-release-notes/react-compiler-monorepo.md b/upcoming-release-notes/react-compiler-monorepo.mdnew file mode 100644index 0000000000..b336e0002d--- /dev/null+++ b/upcoming-release-notes/react-compiler-monorepo.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [MatissJanis]+---++Enable React Compiler for all monorepo packages with React code instead of only desktop-clientdiff --git a/yarn.lock b/yarn.lockindex b8859ae878..5599fcc988 100644--- a/yarn.lock+++ b/yarn.lock@@ -72,6 +72,7 @@ __metadata:dependencies:"@chromatic-com/storybook": "npm:^5.2.1""@emotion/css": "npm:^11.13.5"+ "@rolldown/plugin-babel": "npm:~0.2.3""@storybook/addon-a11y": "npm:^10.4.4""@storybook/addon-docs": "npm:^10.4.4""@storybook/react-vite": "npm:^10.4.4"@@ -82,6 +83,7 @@ __metadata:"@types/react": "npm:^19.2.17""@typescript/native-preview": "npm:beta""@vitejs/plugin-react": "npm:^6.0.2"+ babel-plugin-react-compiler: "npm:^1.0.0"eslint-plugin-storybook: "npm:^10.4.4"react: "npm:19.2.7"react-aria-components: "npm:^1.18.0"