Skip to content

ToastBarPortal: creates orphan roots during suspended renders and accesses document during SSR #2255

Description

@YashAnand69

Description

On main (35f2d19), ToastBarPortal calls ensureAnchorElement during rendering, appending #toastBarRoot to document.body before React commits the component.

Steps to reproduce

  1. Render a Suspense boundary containing ToastBarPortal followed by a sibling that suspends.
  2. The loading fallback is committed; the portal effect never mounts.
  3. An empty #toastBarRoot still remains in document.body, without the effect reference count or cleanup.

Rendering ToastBarPortal with react-dom/server in a Node environment also throws ReferenceError: document is not defined from the same render-time DOM access.

Expected: create/reference the anchor only after mounting, render no portal markup on the server, and preserve root sharing and cleanup across multiple mounted portals.

Both defects are reproduced with failing tests on main. Existing-behavior tests for child updates, shared roots, and StrictMode cleanup pass. Searches found no overlapping open PR; I am preparing an effect-owned portal lifecycle fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions