Skip to content

Commit 0e23f20

Browse files
crisbetothePunderWoman
authored andcommitted
fix(platform-browser): styles not replaced during HMR when using animations renderer (#59393)
When we replace a component during HMR, we clear it from the cache of the renderer factory, however when using animations, there's an animation-specific renderer factory that wraps the base DOM one and was preventing the cache from being cleared. These changes rework the logic that clear the cache to go through a method so we can forward the call to the delegated factory. PR Close #59393
1 parent d1f8834 commit 0e23f20

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

goldens/size-tracking/integration-payloads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"defer": {
4949
"uncompressed": {
50-
"main": 12094,
50+
"main": 12709,
5151
"polyfills": 33807,
5252
"defer.component": 345
5353
}

packages/animations/browser/src/render/animation_renderer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,12 @@ export class AnimationRendererFactory implements RendererFactory2 {
132132
whenRenderingDone(): Promise<any> {
133133
return this.engine.whenRenderingDone();
134134
}
135+
136+
/**
137+
* Used during HMR to clear any cached data about a component.
138+
* @param componentId ID of the component that is being replaced.
139+
*/
140+
protected componentReplaced(componentId: string) {
141+
(this.delegate as {componentReplaced?: (id: string) => void}).componentReplaced?.(componentId);
142+
}
135143
}

packages/core/src/render3/hmr.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ function recreateMatchingLViews(def: ComponentDef<unknown>, rootLView: LView): v
124124
*/
125125
function clearRendererCache(factory: RendererFactory, def: ComponentDef<unknown>) {
126126
// Cast to read a private field.
127-
// NOTE: This must be kept synchronized with the renderer factory implementation in platform-browser.
128-
(factory as {rendererByCompId?: Map<string, unknown>}).rendererByCompId?.delete(def.id);
127+
// NOTE: This must be kept synchronized with the renderer factory implementation in
128+
// platform-browser and platform-browser/animations.
129+
(factory as {componentReplaced?: (id: string) => void}).componentReplaced?.(def.id);
129130
}
130131

131132
/**

packages/platform-browser/src/dom/dom_renderer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ export class DomRendererFactory2 implements RendererFactory2, OnDestroy {
195195
ngOnDestroy() {
196196
this.rendererByCompId.clear();
197197
}
198+
199+
/**
200+
* Used during HMR to clear any cached data about a component.
201+
* @param componentId ID of the component that is being replaced.
202+
*/
203+
protected componentReplaced(componentId: string) {
204+
this.rendererByCompId.delete(componentId);
205+
}
198206
}
199207

200208
class DefaultDomRenderer2 implements Renderer2 {

0 commit comments

Comments
 (0)