Skip to content

fix(core): clean up dehydrated views during HMR component replacement#67689

Open
maxathy wants to merge 1 commit intoangular:mainfrom
maxathy:fix/hmr-dehydrated-views-cleanup
Open

fix(core): clean up dehydrated views during HMR component replacement#67689
maxathy wants to merge 1 commit intoangular:mainfrom
maxathy:fix/hmr-dehydrated-views-cleanup

Conversation

@maxathy
Copy link

@maxathy maxathy commented Mar 14, 2026

Summary

  • During HMR, recreateLView() destroys the old LView but never cleans up dehydrated view DOM nodes stored in LContainer[DEHYDRATED_VIEWS], causing SSR-rendered DOM to persist alongside newly rendered DOM (visible duplication)
  • Calls the existing cleanupLView from the hydration cleanup module after destroyLView in recreateLView() to remove dehydrated DOM before the replacement view renders
  • Adds a test that injects fake dehydrated DOM into an LContainer and verifies HMR cleans it up

Fixes #66503

Test plan

  • Existing HMR acceptance tests pass (//packages/core/test/acceptance:acceptance --test_filter="hot module replacement")
  • New test should clean up dehydrated views from LContainers during HMR passes
  • Manual verification with SSR HMR repro project (edit root component template, refresh — <app-shell> should appear only once)

🤖 Generated with Claude Code

@pullapprove pullapprove bot requested a review from AndrewKushnir March 14, 2026 14:20
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Mar 14, 2026
@ngbot ngbot bot added this to the Backlog milestone Mar 14, 2026
@google-cla

This comment was marked as outdated.

During HMR, `recreateLView()` destroys the old LView and removes its
DOM nodes, but never cleans up dehydrated view DOM nodes stored in
`LContainer[DEHYDRATED_VIEWS]`. These are SSR-rendered DOM nodes
preserved by Angular's hydration system. When the new view renders,
both the old dehydrated DOM and the new DOM coexist, causing visible
duplication (e.g. `<app-shell>` header/footer appearing twice).

Call `cleanupLView` from the hydration cleanup module after
`destroyLView` and before `removeViewFromDOM` to remove any remaining
dehydrated DOM nodes before the replacement view is rendered.

Fixes angular#66503
@maxathy maxathy force-pushed the fix/hmr-dehydrated-views-cleanup branch from 0c91e3a to b60354e Compare March 14, 2026 14:27
@JeanMeche JeanMeche requested a review from crisbeto March 14, 2026 17:04
@AndrewKushnir AndrewKushnir added the target: patch This PR is targeted for the next patch release label Mar 14, 2026
@AndrewKushnir AndrewKushnir removed their request for review March 14, 2026 19:40
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSR dev-server HMR does not dispose hydrated layout, causing duplicated components after root template change

3 participants