Skip to content

Commit

Permalink
fix(components): propagate external changes to secondary renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
simonedevit committed Jan 18, 2025
1 parent b667dbd commit b036bd5
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions packages/library/src/core/Scene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export const Scene: React.FC<SceneProps> = ({ children, sceneOptions, onSceneRea
</Bridge>,
rootContainer.current!,
);

isFirstRender.current = true;
}
})();
Expand All @@ -156,31 +155,19 @@ export const Scene: React.FC<SceneProps> = ({ children, sceneOptions, onSceneRea
}, []);

useEffect(() => {
if (process.env.NODE_ENV === 'test') {
if (!isFirstRender.current) {
const { scene, xrExperience, canvas } = rootContainer.current!;
// Renders children with bridged context into a secondary renderer
Reactylon.render(
<Bridge>
<SceneContext.Provider value={{ engine, isMultipleCanvas, isMultipleScene, scene, xrExperience, canvas }}>{children}</SceneContext.Provider>
</Bridge>,
rootContainer.current!,
);
} else {
isFirstRender.current = false;
}
if (!isFirstRender.current) {
const { scene, xrExperience, canvas } = rootContainer.current!;
// Renders children with bridged context into a secondary renderer
Reactylon.render(
<Bridge>
<SceneContext.Provider value={{ engine, isMultipleCanvas, isMultipleScene, scene, xrExperience, canvas }}>{children}</SceneContext.Provider>
</Bridge>,
rootContainer.current!,
);
} else {
isFirstRender.current = false;
}
});

return null;
};

// USE IT ONLY IF YOU ARE UPDATING ON TOP (e.g. setting state) AND YOU NEED TO RE-RENDER PROVIDERS
/*useEffect(() => {
Reactylon.render(
<Bridge>
<SceneContext.Provider value={{ engine, isMultipleScene, scene, xrExperience, canvas }}>{children}</SceneContext.Provider>
</Bridge>,
rootContainer.current,
);
}, [yourDep]); */

0 comments on commit b036bd5

Please sign in to comment.