Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Portal not rerenders elements with strict mode in React 18 #31

Open
RZholud opened this issue Jul 19, 2022 · 0 comments
Open

Portal not rerenders elements with strict mode in React 18 #31

RZholud opened this issue Jul 19, 2022 · 0 comments

Comments

@RZholud
Copy link

RZholud commented Jul 19, 2022

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

context?.removeOverlayItem(overlayId.current);

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; } }; }, []);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant