File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 10
10
| addTail | Adds a global callback which is called when rendering stops |
11
11
| buildGraph | Collects nodes and materials from a THREE.Object3D |
12
12
| flushGlobalEffects | Flushes global render-effects for when manually driving a loop |
13
+ | flushSync | Force React to flush any updates synchronously and immediately |
13
14
| invalidate | Forces view global invalidation |
14
15
| advance | Advances the frameloop (given that it's set to 'never') |
15
16
| extend | Extends the native-object catalogue |
Original file line number Diff line number Diff line change @@ -597,6 +597,17 @@ function Portal({
597
597
)
598
598
}
599
599
600
+ /**
601
+ * Force React to flush any updates inside the provided callback synchronously and immediately.
602
+ * All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
603
+ * Nevertheless, sometimes one needs to render synchronously, for example to keep DOM and 3D changes in lock-step without
604
+ * having to revert to a non-React solution.
605
+ */
606
+ function flushSync < R > ( fn : ( ) => R ) : R {
607
+ // `flushSync` implementation only takes one argument. I don't know what's up with the type declaration for it.
608
+ return reconciler . flushSync ( fn , undefined )
609
+ }
610
+
600
611
reconciler . injectIntoDevTools ( {
601
612
bundleType : process . env . NODE_ENV === 'production' ? 0 : 1 ,
602
613
rendererPackageName : '@react-three/fiber' ,
@@ -622,6 +633,7 @@ export {
622
633
addAfterEffect ,
623
634
addTail ,
624
635
flushGlobalEffects ,
636
+ flushSync ,
625
637
getRootState ,
626
638
act ,
627
639
buildGraph ,
You can’t perform that action at this time.
0 commit comments