File tree Expand file tree Collapse file tree
packages/runtime/src/render Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,21 @@ import { useRenderedElement } from '../ui/state.js';
44import { store } from '../ui/state.js' ;
55import { ErrorBoundary } from './ErrorBoundary.js' ;
66
7+ /**
8+ * Waits for the native view hierarchy to be fully updated.
9+ * Uses double requestAnimationFrame to ensure native has processed
10+ * all view creation commands after React's commit phase.
11+ */
12+ const waitForNativeViewHierarchy = ( ) : Promise < void > => {
13+ return new Promise ( ( resolve ) => {
14+ requestAnimationFrame ( ( ) => {
15+ requestAnimationFrame ( ( ) => {
16+ resolve ( ) ;
17+ } ) ;
18+ } ) ;
19+ } ) ;
20+ } ;
21+
722export const TestComponentOverlay = ( ) : React . ReactElement | null => {
823 const { element, key } = useRenderedElement ( ) ;
924
@@ -12,8 +27,13 @@ export const TestComponentOverlay = (): React.ReactElement | null => {
1227 const callback = store . getState ( ) . onRenderCallback ;
1328
1429 if ( callback ) {
15- callback ( ) ;
16- store . getState ( ) . setOnRenderCallback ( null ) ;
30+ // Wait for native view hierarchy to be fully updated before calling callback.
31+ // useEffect fires after React commits, but native processes commands async.
32+ // Double rAF ensures native has finished processing all view creation.
33+ waitForNativeViewHierarchy ( ) . then ( ( ) => {
34+ callback ( ) ;
35+ store . getState ( ) . setOnRenderCallback ( null ) ;
36+ } ) ;
1737 }
1838 } , [ element ] ) ;
1939
You can’t perform that action at this time.
0 commit comments