Skip to content

Commit cc545e9

Browse files
authored
Merge pull request #3508 from pmndrs/fix-react19-act
Fix builds failing from React.act being removed from the production bundle
2 parents e238c9d + fdf0705 commit cc545e9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/thick-rice-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@react-three/fiber': patch
3+
---
4+
5+
Fix failing builds for production when React.act is unavailable. This fixes issues found in [email protected] and up.

packages/fiber/src/core/utils.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ export type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
3131
/**
3232
* Safely flush async effects when testing, simulating a legacy root.
3333
*/
34-
export const act: Act = (React as any).act
34+
export const act: Act = (cb) => {
35+
if ('act' in React) {
36+
return React.act(cb)
37+
}
38+
39+
throw new Error('act(...) is not supported in production builds of React')
40+
}
3541

3642
export type Camera = (THREE.OrthographicCamera | THREE.PerspectiveCamera) & { manual?: boolean }
3743
export const isOrthographicCamera = (def: Camera): def is THREE.OrthographicCamera =>

0 commit comments

Comments
 (0)