react-native-aria icon indicating copy to clipboard operation
react-native-aria copied to clipboard

Portal not rerenders elements with strict mode in React 18

Open RZholud opened this issue 3 years ago • 0 comments

React version: 18.2.0

Steps To Reproduce

  1. Use React.StrictMode
  2. Use portal inside strictmode block.

The current behavior

  1. Portal unmounts element based on strictmode behaviour, but not unsets refs
  2. Value of overlayId stays old, but this overlay already destroyed and can't be updated

The expected behavior

  1. After unmount and removing portal elements, overylayId.current should become undefined again, then it will work fine and portal will mount elements again.

Broken code part https://github.com/GeekyAnts/react-native-aria/blob/ec14df07ea1273f81e73eeb4ac41f63d455495b1/packages/overlays/src/Portal.tsx#L106 React 18 strict mode changes https://reactjs.org/blog/2022/03/29/react-v18.html#new-strict-mode-behaviors Estimated fix useEffect(() => { return () => { if (overlayId.current) { context?.removeOverlayItem(overlayId.current); overlayId.current = undefined; } }; }, []);

RZholud avatar Jul 19 '22 11:07 RZholud