Skip to content

Commit c878c90

Browse files
committed
feat: react compiler behind a flag
1 parent edefb82 commit c878c90

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

app/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ export PHOENIX_SMTP_USERNAME=apikey
66
export PHOENIX_SMTP_PASSWORD=XXXXXXXXXXXXXXXX
77
# Used for running chromatic visual tests on components
88
export CHROMATIC_PROJECT_TOKEN=XXXXXXX
9+
# Use the react-compiler
10+
export PHOENIX_USE_REACT_COMPILER=True

app/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Before running the script above you should configure your running environment by
3030

3131
Depending on what flows you are trying to build features for, you may want to adjust the scripts block within the [package.json](./package.json) file so that the server is serving the appropriate fixture data.
3232

33+
### Environment Variables
34+
35+
The following environment variables can be configured in your `.env` file:
36+
37+
- **`PHOENIX_USE_REACT_COMPILER`**: Enable or disable the React Compiler for improved performance. Set to `True` (capital T) to enable, or omit/leave unset to disable. The React Compiler can improve performance but may introduce new errors, so proceed with caution when enabling it.
38+
3339
### Authentication
3440

3541
For local development, you have two options for authentication:

app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"@types/relay-runtime": "^19.0.3",
9393
"@types/three": "^0.180.0",
9494
"@vitejs/plugin-react": "^4.7.0",
95+
"babel-plugin-react-compiler": "1.0.0",
9596
"babel-plugin-relay": "^20.1.1",
9697
"chromatic": "^11.29.0",
9798
"cpy-cli": "^5.0.0",
@@ -126,10 +127,10 @@
126127
"test:watch": "vitest",
127128
"test:e2e": "playwright test",
128129
"test:e2e:ui": "playwright test --ui",
129-
"dev": "pnpm run dev:server & pnpm run build:static && pnpm run build:relay && vite",
130+
"dev": "pnpm run dev:server & pnpm run dev:ui",
130131
"dev:offline": "pnpm run dev:server:offline & pnpm run build:static && pnpm run build:relay && vite",
131132
"dev:embeddings": "pnpm run dev:server:embeddings & pnpm run build:static && pnpm run build:relay && vite",
132-
"dev:ui": "pnpm run build:static && pnpm run build:relay && vite",
133+
"dev:ui": "source ./.env && pnpm run build:static && pnpm run build:relay && vite",
133134
"dev:server": "source ./.env && uv run --compile --with-requirements=../requirements/dev.txt phoenix --dev serve",
134135
"dev:server:offline": "python -m phoenix.server.main --dev serve",
135136
"dev:server:embeddings": "pnpm dev:server --with-fixture=fashion_mnist",

app/pnpm-lock.yaml

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

app/vite.config.mts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,33 @@ import { defineConfig } from "vite";
88
import reactFallbackThrottlePlugin from "vite-plugin-react-fallback-throttle";
99
import relay from "vite-plugin-relay";
1010

11+
const useReactCompiler = process.env.PHOENIX_ENABLE_REACT_COMPILER === "True";
12+
13+
if (useReactCompiler) {
14+
// eslint-disable-next-line no-console
15+
console.log(
16+
"🔥 Using React Compiler. This will improve performance but also may introduce new errors. Proceed with caution."
17+
);
18+
} else {
19+
// eslint-disable-next-line no-console
20+
console.log("⏼ React compiler is disabled.");
21+
}
1122
export default defineConfig(() => {
1223
const plugins = [
1324
// disable react's built-in 300ms suspense fallback timer
1425
// without this build plugin we see a 300ms delay on most UI interactions
1526
reactFallbackThrottlePlugin(),
16-
react(),
27+
react(
28+
useReactCompiler
29+
? {
30+
babel: {
31+
plugins: [
32+
["babel-plugin-react-compiler", { panicThreshold: "none" }],
33+
],
34+
},
35+
}
36+
: {}
37+
),
1738
relay,
1839
lezer(),
1940
];

0 commit comments

Comments
 (0)