fix(core): clean up dehydrated views during HMR component replacement#67689
Open
maxathy wants to merge 1 commit intoangular:mainfrom
Open
fix(core): clean up dehydrated views during HMR component replacement#67689maxathy wants to merge 1 commit intoangular:mainfrom
maxathy wants to merge 1 commit intoangular:mainfrom
Conversation
This comment was marked as outdated.
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
0c91e3a to
b60354e
Compare
crisbeto
approved these changes
Mar 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
recreateLView()destroys the old LView but never cleans up dehydrated view DOM nodes stored inLContainer[DEHYDRATED_VIEWS], causing SSR-rendered DOM to persist alongside newly rendered DOM (visible duplication)cleanupLViewfrom the hydration cleanup module afterdestroyLViewinrecreateLView()to remove dehydrated DOM before the replacement view rendersFixes #66503
Test plan
//packages/core/test/acceptance:acceptance --test_filter="hot module replacement")should clean up dehydrated views from LContainers during HMRpasses<app-shell>should appear only once)🤖 Generated with Claude Code