[v9] Unmounting doesn't request a frame with frameloop="demand" (regression since v9)
With frameloop="demand", unmounting an object doesn't request a frame, so it stays on screen until something else causes a render. Mounting and prop changes still request frames, only removal doesn't. This worked in v8.
Repro
https://stackblitz.com/edit/gyxd9rxa?file=src%2FApp.jsx
<Canvas frameloop="demand"> with a conditionally rendered mesh and a frame counter. Click Unmount red box: the box stays on screen and no frame is rendered until something else calls invalidate(). Mounting it again renders a frame as expected. With @react-three/[email protected] the same code renders a frame on unmount.
Versions: @react-three/fiber 9.8.1 (also current v10), three 0.186.1, react 19.3.0.
Cause
removeChild clears the child's parent first and requests the frame last:
child.parent = null
// ...
if (dispose === undefined) invalidateInstance(child)invalidateInstance then returns immediately:
export function invalidateInstance(instance: Instance): void {
if (!instance.parent) return
// ...
}History
- v8: the "only if attached" check only decided whether
onUpdateran (applyProps, #2548).invalidateInstancehad no check, so removal always requested a frame. - #2480 removed
onUpdatefrom the v9 branch. - 8294bdbc ("fix: restore onUpdate") brought
onUpdateback insideinvalidateInstanceand put the check at the top of the function. Since then it blocks the frame request as well, and removal never redraws. - #3930 removed
onUpdateagain onv10but keptif (!instance.parent) return. The check has nothing left to protect, and removal still doesn't request a frame.
Suggested fix
On v10, drop the check. On 9.x, limit it to onUpdate:
export function invalidateInstance(instance: Instance): void {
if (instance.parent) instance.props.onUpdate?.(instance.object)
const state = instance.root?.getState?.()
if (state && state.internal.frames === 0) state.invalidate()
}removeChild doesn't touch instance.root, so this requests the frame on removal again.
Source: pmndrs/react-three-fiber