From 24b784e9bb5c88d25e95ebc796509fa38b237b4e Mon Sep 17 00:00:00 2001 From: WebPerson Date: Tue, 1 Sep 2026 22:10:59 -0500 Subject: [PATCH] [Performance] Enable React Compiler for automatic memoization (#11783) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(ui): enable React Compiler (#67) Enable reactCompiler: true in next.config.mjs (Next 16 + React 19.2.8). This automates memoization at build time, removing manual useCallback/useMemo debt (591 + 283 instances respectively) and preventing stale-closure bugs. Test results (pre-existing failures unchanged): vitest UI: 282/295 files pass (13 fail = missing router/ReactFlow mocks) vitest: 1805/1857 tests pass (52 fail = same pre-existing mock issues) node:test: api/services/db all pass (except platform-specific serviceSupervisorSpawnError — Windows spawn("ls") issue) No new failures introduced by the compiler transform. Optional cleanup: remove now-redundant useCallback/useMemo in hot components. * fix(build): add babel-plugin-react-compiler peer dependency (#67) React Compiler (reactCompiler: true in next.config.mjs) requires babel-plugin-react-compiler as an explicit peer dependency — Next.js declares it as optional ("*") and does not auto-install it. Installed babel-plugin-react-compiler@1.0.0 as a devDependency. Resolves correctly from both the project root and the next package context (Turbopack resolution path). * fix(ci): allowlist babel-plugin-react-compiler for React Compiler The React Compiler peer is a real npm package (facebook/react, MIT) required by Next 16 `reactCompiler: true`. Adding it to the anti-slopsquat allowlist unblocks check:deps and the 6A.8 unit-test gate. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(ci): drop unused collectSSE helper that trips ESLint The helper was leftover from #12151 and fails the absolute lint:json --max-warnings 0 gate on every PR that includes it. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: WebPerson --- changelog.d/features/11783-react-compiler.md | 1 + config/quality/dependency-allowlist.json | 2 ++ next.config.mjs | 3 +++ package-lock.json | 11 +++++++++++ package.json | 1 + tests/unit/next-config.test.ts | 2 ++ 6 files changed, 20 insertions(+) create mode 100644 changelog.d/features/11783-react-compiler.md diff --git a/changelog.d/features/11783-react-compiler.md b/changelog.d/features/11783-react-compiler.md new file mode 100644 index 0000000000..9c38f22557 --- /dev/null +++ b/changelog.d/features/11783-react-compiler.md @@ -0,0 +1 @@ +- **feat(ui):** enable React Compiler (`reactCompiler: true` + `babel-plugin-react-compiler`) for automatic memoization at build time ([#11783](https://github.com/diegosouzapw/OmniRoute/pull/11783)) — thanks @jonlwheat2-gif diff --git a/config/quality/dependency-allowlist.json b/config/quality/dependency-allowlist.json index ef32957851..e29948160e 100644 --- a/config/quality/dependency-allowlist.json +++ b/config/quality/dependency-allowlist.json @@ -3,6 +3,7 @@ "_justifications": { "@testing-library/dom": "Peer dep obrigatoria de @testing-library/react v16 (adicionada no PR #11224); Refs #9985.", "@testing-library/user-event": "Utilitario oficial do ecossistema testing-library para testes de UI (adicionada no PR #11224); Refs #9985.", + "babel-plugin-react-compiler": "Official React Compiler Babel plugin (facebook/react, MIT). Required peer of Next.js 16 `reactCompiler: true`; Next declares it optional (`*`) and does not auto-install. Added by PR #11783 / issue #67.", "eslint-plugin-react-hooks": "React Hooks lint rules (set-state-in-effect, immutability, refs, purity) pinned at 7.0.1 by the release/v3.8.51 cycle; the 224 findings it raised are tracked in #11924. Refs #11924." }, "allowed": [ @@ -44,6 +45,7 @@ "ajv", "ajv-formats", "axios", + "babel-plugin-react-compiler", "bcryptjs", "better-sqlite3", "bottleneck", diff --git a/next.config.mjs b/next.config.mjs index e384d2d88f..c5b9899adb 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -223,6 +223,9 @@ const nextConfig = { ...(isContributorBuild ? {} : { output: "standalone" }), compress: true, productionBrowserSourceMaps: false, + // Issue #67: enable React Compiler — automates memoization, removes manual useCallback/useMemo debt. + // See: https://next.dev/blog/react-compiler + reactCompiler: true, // OmniRoute is a proxy for AI APIs — request bodies routinely include // multi-MB payloads (vision models, image edits, base64-encoded files, // long chat histories with embedded images). Next.js's Server Action diff --git a/package-lock.json b/package-lock.json index 0e942c17d8..4b71b7e3b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -122,6 +122,7 @@ "@types/safe-regex": "^1.1.6", "@types/ws": "^8.18.0", "@vitejs/plugin-react": "^6.1.0", + "babel-plugin-react-compiler": "^1.0.0", "bun": "1.4.0", "c8": "^12.0.0", "concurrently": "^10.0.5", @@ -16173,6 +16174,16 @@ "npm": ">=6" } }, + "node_modules/babel-plugin-react-compiler": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/babel-plugin-react-compiler/-/babel-plugin-react-compiler-1.0.0.tgz", + "integrity": "sha512-Ixm8tFfoKKIPYdCCKYTsqv+Fd4IJ0DQqMyEimo+pxUOMUR9cVPlwTrFt9Avu+3cb6Zp3mAzl+t1MrG2fxxKsxw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.26.0" + } + }, "node_modules/babel-walk": { "version": "3.0.0-canary-5", "resolved": "https://registry.npmjs.org/babel-walk/-/babel-walk-3.0.0-canary-5.tgz", diff --git a/package.json b/package.json index 8f12f4272e..f315bcd433 100644 --- a/package.json +++ b/package.json @@ -386,6 +386,7 @@ "@types/safe-regex": "^1.1.6", "@types/ws": "^8.18.0", "@vitejs/plugin-react": "^6.1.0", + "babel-plugin-react-compiler": "^1.0.0", "bun": "1.4.0", "c8": "^12.0.0", "concurrently": "^10.0.5", diff --git a/tests/unit/next-config.test.ts b/tests/unit/next-config.test.ts index 589255d837..9503a9b4ea 100644 --- a/tests/unit/next-config.test.ts +++ b/tests/unit/next-config.test.ts @@ -30,6 +30,8 @@ test("next config exposes standalone build settings and canonical rewrites", asy assert.equal(nextConfig.distDir, ".next-task607"); assert.equal(nextConfig.output, "standalone"); + // #67 / #11783: React Compiler is an explicit Next 16 opt-in (peer babel plugin). + assert.equal(nextConfig.reactCompiler, true); assert.equal(nextConfig.images.unoptimized, true); assert.deepEqual(nextConfig.transpilePackages, [ "@omniroute/open-sse",