react-three-flex icon indicating copy to clipboard operation
react-three-flex copied to clipboard

Correct node ordering on mount/unmount

Open giulioz opened this issue 5 years ago • 1 comments

giulioz avatar Sep 03 '20 15:09 giulioz

If something unmounts-mounts it will be placed to the end of the flex, ignoring ordering: https://github.com/react-spring/react-three-flex/blob/master/src/Box.tsx#L186

  // Make child known to the parents yoga instance *before* it calculates layout
  useLayoutEffect(() => {
    if (!group.current) return () => {}

    parent.insertChild(node, parent.getChildCount())
    registerBox(group.current, node, flexProps, centerAnchor)

    // Remove child on unmount
    return () => {
      parent.removeChild(node)
      if (group.current) {
        unregisterBox(group.current, node)
      }
    }
  }, [node, parent, flexProps, centerAnchor])

giulioz avatar Sep 04 '20 20:09 giulioz