Skip to content

Commit 6d00efd

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 a77bc0e commit 6d00efd

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

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
@@ -184,6 +184,14 @@ export class DomRendererFactory2 implements RendererFactory2, OnDestroy {
184184
ngOnDestroy() {
185185
this.rendererByCompId.clear();
186186
}
187+
188+
/**
189+
* Used during HMR to clear any cached data about a component.
190+
* @param componentId ID of the component that is being replaced.
191+
*/
192+
protected componentReplaced(componentId: string) {
193+
this.rendererByCompId.delete(componentId);
194+
}
187195
}
188196

189197
class DefaultDomRenderer2 implements Renderer2 {

0 commit comments

Comments
 (0)