Skip to content

Commit

Permalink
fix: patch for React 18.2 rendering differences
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzinn committed Sep 3, 2022
1 parent 8eb4636 commit bc66dd8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/react-babylonjs/src/Engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const ReactBabylonjsEngine: React.FC<EngineProps> = (props: EngineProps, context
...canvasProps
} = props

const observerEnabled = renderOptions !== undefined && renderOptions.whenVisibleOnly === true && !isPaused
const observerEnabled =
renderOptions !== undefined && renderOptions.whenVisibleOnly === true && !isPaused
useCanvasObserver(canvasRef, shouldRenderRef, observerEnabled, 0)

useEffect(() => {
Expand Down Expand Up @@ -138,7 +139,10 @@ const ReactBabylonjsEngine: React.FC<EngineProps> = (props: EngineProps, context

// TODO: here is where you could access your own render method
engine.current!.scenes.forEach((scene) => {
scene.render()
// TODO (fix properly): in React 18.2 (not 18.0 or 18.1 if the camera is in a subcomponent it will be added in a future render!)
if (scene.cameras?.length > 0) {
scene.render()
}
})

if (onEndRenderLoopObservable.current.hasObservers()) {
Expand Down

0 comments on commit bc66dd8

Please sign in to comment.