Skip to content

Commit a0de2ea

Browse files
committed
fix: use R3F v8 for React 18 projects to prevent reconciler crash
- R3F v9 requires React 19 using v9 with React 18 causes TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner') - Pin R3F v8.18.0 + drei v9.122.0 for React 18 projects (default) - Pin R3F v9.5.0 + drei v10.7.7 for React 19 projects only - Add Vite optimizeDeps.include guidance for three/r3f/drei - Explicit warning about version mismatch in system prompt
1 parent c0a6538 commit a0de2ea

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

app/lib/common/prompts/new-prompt.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,35 @@ export const getFineTunedPrompt = (
8484
or any Three.js-related functionality:
8585
8686
ALWAYS prefer React Three Fiber (@react-three/fiber) and its ecosystem.
87-
CRITICAL: Use these EXACT package versions — do NOT invent version numbers:
88-
- three@^0.183.0 — Three.js core (ALWAYS include as dependency)
89-
- @react-three/fiber@^9.5.0 — Core React renderer for Three.js
90-
- @react-three/drei@^10.7.7Useful helpers, controls, abstractions
91-
- @react-three/postprocessing@^3.0.4Post-processing effects (bloom, vignette, etc.)
92-
- @react-three/rapierPhysics engine integration
87+
88+
CRITICAL VERSION RULES — do NOT invent version numbers:
89+
For React 18 projects (default for most Vite templates):
90+
- three@^0.170.0Three.js core (ALWAYS include as dependency)
91+
- @react-three/fiber@^8.18.0R3F v8 for React 18 (DO NOT use v9 with React 18!)
92+
- @react-three/drei@^9.122.0Helpers for R3F v8
9393
- react-error-boundary@^5.0.0 — Error boundary for graceful 3D fallbacks (ALWAYS include)
94+
For React 19 projects only:
95+
- three@^0.183.0
96+
- @react-three/fiber@^9.5.0 — R3F v9 requires React 19
97+
- @react-three/drei@^10.7.7
98+
- react-error-boundary@^5.0.0
99+
100+
CRITICAL: R3F v9 is INCOMPATIBLE with React 18. Using v9 with React 18 causes:
101+
"TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')"
102+
If the project uses React 18 (check package.json), you MUST use R3F v8 + drei v9.
94103
95104
CRITICAL DEPENDENCY RULE: Every package you import in code MUST be in package.json.
96105
Before writing ANY import statement, verify the package is listed in dependencies or devDependencies.
97-
Install command: npm install three @react-three/fiber @react-three/drei react-error-boundary
106+
Install command (React 18): npm install three@^0.170.0 @react-three/fiber@^8.18.0 @react-three/drei@^9.122.0 react-error-boundary
98107
99108
R3F Best Practices:
100109
- Use declarative JSX for the scene graph (<Canvas>, <mesh>, <ambientLight>, etc.)
101110
- Always wrap 3D content in a <Canvas> component
102111
- Use React.lazy() + Suspense for 3D scenes to handle loading gracefully
103112
- Wrap 3D content in an ErrorBoundary (from react-error-boundary) for graceful fallback
104113
- ALWAYS ensure "vite" is in devDependencies when creating Vite projects
114+
- Add 'three' to vite.config.ts optimizeDeps.include for proper pre-bundling:
115+
optimizeDeps: { include: ['three', '@react-three/fiber', '@react-three/drei'] }
105116
- Reference: https://r3f.docs.pmnd.rs/getting-started/introduction
106117
107118
When R3F is NOT suitable (use alternatives instead):

0 commit comments

Comments
 (0)