Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/animations/browser/src/render/animation_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export class AnimationRendererFactory implements RendererFactory2 {
* @param componentId ID of the component that is being replaced.
*/
protected componentReplaced(componentId: string) {
// Flush the engine since the renderer destruction waits for animations to be done.
this.engine.flush();
(this.delegate as {componentReplaced?: (id: string) => void}).componentReplaced?.(componentId);
}
}
17 changes: 11 additions & 6 deletions packages/core/src/render3/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
LViewFlags,
NEXT,
PARENT,
RENDERER,
T_HOST,
TVIEW,
} from './interfaces/view';
Expand Down Expand Up @@ -156,11 +157,6 @@ function recreateLView(
// Recreate the TView since the template might've changed.
const newTView = getOrCreateComponentTView(newDef);

// Always force the creation of a new renderer to ensure state captured during construction
// stays consistent with the new component definition by clearing any old cached factories.
const rendererFactory = lView[ENVIRONMENT].rendererFactory;
clearRendererCache(rendererFactory, oldDef);

// Create a new LView from the new TView, but reusing the existing TNode and DOM node.
const newLView = createLView(
parentLView,
Expand All @@ -170,7 +166,7 @@ function recreateLView(
host,
tNode,
null,
rendererFactory.createRenderer(host, newDef),
null, // The renderer will be created a bit further down once the old one is destroyed.
null,
null,
null,
Expand All @@ -183,6 +179,15 @@ function recreateLView(
// Destroy the detached LView.
destroyLView(lView[TVIEW], lView);

// Always force the creation of a new renderer to ensure state captured during construction
// stays consistent with the new component definition by clearing any old ached factories.
const rendererFactory = lView[ENVIRONMENT].rendererFactory;
clearRendererCache(rendererFactory, oldDef);

// Patch a brand-new renderer onto the new view only after the old
// view is destroyed so that the runtime doesn't try to reuse it.
newLView[RENDERER] = rendererFactory.createRenderer(host, newDef);

// Remove the nodes associated with the destroyed LView. This removes the
// descendants, but not the host which we want to stay in place.
removeViewFromDOM(lView[TVIEW], lView);
Expand Down
Loading