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

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

@RZholud

Description

@RZholud

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions