Skip to content

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

Merged
mattrbeck merged 1 commit into
angular:mainfrom
maxmillienjr:fix/hmr-dehydrated-views-cleanup
Mar 16, 2026
Merged

fix(core): clean up dehydrated views during HMR component replacement#67689
mattrbeck merged 1 commit into
angular:mainfrom
maxmillienjr:fix/hmr-dehydrated-views-cleanup

Conversation

@maxmillienjr

@maxmillienjr maxmillienjr commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

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 #66503
@maxmillienjr maxmillienjr 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
@mattrbeck mattrbeck merged commit dc04465 into angular:main Mar 16, 2026
21 checks passed
@mattrbeck

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

@maxmillienjr maxmillienjr deleted the fix/hmr-dehydrated-views-cleanup branch March 16, 2026 17:20
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

4 participants