Skip to content

cacheComponents breaks React Portal cleanup — portaled content stays stuck after route change #85390

@SorooshGb

Description

@SorooshGb

Link to the code that reproduces this issue

https://github.com/SorooshGb/nextjs-portal-cache-issue-repro

To Reproduce

  1. Clone the repo linked above and run npm install.
  2. Start the app with npm run dev.
  3. Open the Home page (/) — you’ll see 4 dropdown menus, each using a different implementation:
    • Radix UI / shadcn dropdown
    • Raw React portal example
    • React Aria popover
    • Headless UI popover
  4. Open any of the dropdowns/popovers.
  5. Inside each one, click the link that navigates to /dashboard.
  6. After navigation, notice that the portaled content remains visible on the new route and doesn’t go away until you refresh the page.

Current vs. Expected behavior

Current behavior:
When cacheComponents: true is enabled in Next.js 16, any open portal (dropdown, popover, modal, etc.) stays visible on the screen after navigation and becomes completely non-interactive.
Its DOM node persists in the document and can only be cleared by refreshing the page.

Expected behavior:
Portal content should disappear (be unmounted) automatically when navigating to a new route, as it does when cacheComponents is set to false or in previous Next.js versions.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 32493
  Available CPU cores: 12
Binaries:
  Node: 22.16.0
  npm: 11.4.2
  Yarn: 1.22.22
  pnpm: 10.13.1
Relevant Packages:
  next: 16.0.0 // Latest available version is detected (16.0.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

cacheComponents

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

This issue appears to have been introduced in Next.js 16 — it does not happen in previous versions.
A comment in the related issue (#85218) points to a specific PR that might have caused it:
#85218 (comment)

I’m creating this new issue with a more accurate title to bring attention to how critical this problem is, since the existing reports don’t fully explain or demonstrate it:

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