Skip to content

core: hydration retains the first routed SSR DOM through segmentHeads after navigation #72010

Open

Description

@Rambuto

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

In Angular 22.2.6, the DOM of the initially server-rendered routed component remains in memory after navigating away from that route.

The component’s ngOnDestroy() runs and its host is disconnected from the document, but the root view’s hydration data still holds a strong reference to it:

Root component LView → LView[HYDRATION] → segmentHeads[0] → detached initial route component host → its DOM subtree

Forced garbage collection does not release the subtree.

Reproduction

I reproduced this in a minimal application with:

  • A root component containing only <router-outlet />.
  • Route /, rendering a component with 1,000 paragraphs.
  • Route /b, rendering another component with one paragraph.
  • SSR and provideClientHydration().

There are no third-party widgets, application services, template event listeners, i18n blocks, @defer blocks, or custom route reuse strategy.

Before bootstrap, I stored only a WeakRef to the original SSR component host. After bootstrap, I verified that hydration reused that exact node.

I then navigated to /b, waited for application stability and browser tasks, and forced garbage collection through CDP’s HeapProfiler.collectGarbage. I repeated this across four navigation cycles.

Actual behavior

Configuration Original SSR host retained after navigation and GC
provideClientHydration() Yes, all four cycles
provideClientHydration(withNoIncrementalHydration()) Yes, all four cycles
No hydration providers No; the original SSR DOM is replaced at bootstrap

In both hydrated configurations:

  • ngOnDestroy() runs.
  • The original host has isConnected === false.
  • segmentHeads still references the original host.
  • The original host survives forced garbage collection.

Subsequent client-created instances were collected in the recorded run. This appears to be bounded retention of the initial SSR subtree rather than an unbounded leak on every navigation.

The no-hydration case is a control: the original SSR DOM is replaced during bootstrap, so it is not a like-for-like measurement of the later client-created DOM.

Expected behavior

Once the initially hydrated routed component has been destroyed, obsolete hydration bookkeeping in a surviving ancestor view should not prevent its DOM from being garbage-collected.

Investigation

In the installed Angular 22.2.6 code, setSegmentHead() stores strong DOM references.

The inspected cleanup path clears i18n hydration data and traverses child views and containers, but leaves segmentHeads in place.

Any cleanup fix would need to preserve metadata still required by pending incremental hydration.

The diagnostic code only reads Angular internals; it does not modify them. DOM nodes were not logged, returned as DevTools handles, or retained through element selection. No performance traces were recorded.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular packages: 22.2.6 (core, common, compiler, platform-browser, platform-server, router)
Node.js:         24.22.1
OS / arch:       macOS / arm64
Chrome:          157.0.8103.51 (headless)
Playwright:      1.62.1
esbuild:         0.28.2
RxJS:            7.8.2
Change detection: zoneless
Rendering:       SSR followed by client hydration
Compilation:     JIT, enableProdMode(), browser ngDevMode=false


This standalone harness does not use the Angular CLI or an AOT production build.
The same retention path was originally observed in an application production
build; the attached evidence is from the isolated JIT reproduction above.

Anything else?

Event replay issue #66506
describes a different retention path. This report remains reproducible with
incremental hydration disabled and with no event listeners, so disabling event
replay does not resolve the observed segmentHeads retention.

Activity

  1. added
    area: core
    on Nov 12, 2026
  2. added this to the needsTriage milestone on Nov 12, 2026
  3. seragAhmed commented on Nov 13, 2026

    @seragAhmed

    Hi! Could I investigate this? I’d start with a router hydration test that navigates away from the initial server-rendered route and checks whether segmentHeads still references the old DOM. I’d also verify that removing stale references preserves the active route’s behavior.

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

    area: core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions