Skip to content

Commit 02d5e8d

Browse files
alan-agius4alxhub
authored andcommitted
fix(platform-browser): remove styles from DOM of destroyed components (#48298)
Currently style of components using `encapsulation`, `None` or `Emulated` will not be removed from the DOM once the component get destroyed. This change addresses this by keeping track of the number of times a component is rendered, when the component is destroyed the counter is decreased and once this reaches zero the style element is removed from the DOM. Currently, this new behaviour is on opt-in bases, but it will be changed in the next major version. To opt-in, set the `REMOVE_STYLES_ON_COMPONENT_DESTROY` DI token to `true`. Example ```ts @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule ], providers: [ { provide: REMOVE_STYLES_ON_COMPONENT_DESTROY, useValue: true } ], bootstrap: [AppComponent] }) export class AppModule { } ``` Closes #16670 PR Close #48298
1 parent f3f1399 commit 02d5e8d

File tree

18 files changed

+446
-154
lines changed

18 files changed

+446
-154
lines changed

goldens/public-api/platform-browser/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export const platformBrowser: (extraProviders?: StaticProvider[]) => PlatformRef
183183
// @public
184184
export function provideProtractorTestingSupport(): Provider[];
185185

186+
// @public
187+
export const REMOVE_STYLES_ON_COMPONENT_DESTROY: InjectionToken<boolean>;
188+
186189
// @public
187190
export interface SafeHtml extends SafeValue {
188191
}

goldens/size-tracking/aio-payloads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"aio-local": {
1313
"uncompressed": {
1414
"runtime": 4325,
15-
"main": 466290,
15+
"main": 467355,
1616
"polyfills": 33836,
1717
"styles": 74561,
1818
"light-theme": 92890,

goldens/size-tracking/integration-payloads.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cli-hello-world": {
33
"uncompressed": {
44
"runtime": 908,
5-
"main": 125165,
5+
"main": 126185,
66
"polyfills": 33824
77
}
88
},
@@ -19,43 +19,43 @@
1919
"cli-hello-world-ivy-compat": {
2020
"uncompressed": {
2121
"runtime": 930,
22-
"main": 132182,
22+
"main": 133202,
2323
"polyfills": 33957
2424
}
2525
},
2626
"cli-hello-world-ivy-i18n": {
2727
"uncompressed": {
2828
"runtime": 926,
29-
"main": 123543,
29+
"main": 125026,
3030
"polyfills": 34628
3131
}
3232
},
3333
"cli-hello-world-lazy": {
3434
"uncompressed": {
3535
"runtime": 2734,
36-
"main": 228122,
36+
"main": 229111,
3737
"polyfills": 33842,
3838
"src_app_lazy_lazy_routes_ts": 487
3939
}
4040
},
4141
"forms": {
4242
"uncompressed": {
4343
"runtime": 888,
44-
"main": 157604,
44+
"main": 158624,
4545
"polyfills": 33915
4646
}
4747
},
4848
"animations": {
4949
"uncompressed": {
5050
"runtime": 898,
51-
"main": 156355,
51+
"main": 157699,
5252
"polyfills": 33897
5353
}
5454
},
5555
"standalone-bootstrap": {
5656
"uncompressed": {
5757
"runtime": 918,
58-
"main": 84527,
58+
"main": 85547,
5959
"polyfills": 33945
6060
}
6161
},

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@
401401
{
402402
"name": "NodeInjectorFactory"
403403
},
404+
{
405+
"name": "NoneEncapsulationDomRenderer"
406+
},
404407
{
405408
"name": "NoopAnimationDriver"
406409
},
@@ -440,6 +443,9 @@
440443
{
441444
"name": "REMOVAL_FLAG"
442445
},
446+
{
447+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
448+
},
443449
{
444450
"name": "RefCountOperator"
445451
},
@@ -1310,9 +1316,6 @@
13101316
{
13111317
"name": "removeNodesAfterAnimationDone"
13121318
},
1313-
{
1314-
"name": "removeStyle"
1315-
},
13161319
{
13171320
"name": "renderComponent"
13181321
},

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@
296296
{
297297
"name": "NodeInjectorFactory"
298298
},
299+
{
300+
"name": "NoneEncapsulationDomRenderer"
301+
},
299302
{
300303
"name": "NullInjector"
301304
},
@@ -320,6 +323,9 @@
320323
{
321324
"name": "R3Injector"
322325
},
326+
{
327+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
328+
},
323329
{
324330
"name": "RefCountOperator"
325331
},
@@ -998,9 +1004,6 @@
9981004
{
9991005
"name": "removeFromArray"
10001006
},
1001-
{
1002-
"name": "removeStyle"
1003-
},
10041007
{
10051008
"name": "renderComponent"
10061009
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@
407407
{
408408
"name": "NodeInjectorFactory"
409409
},
410+
{
411+
"name": "NoneEncapsulationDomRenderer"
412+
},
410413
{
411414
"name": "NullInjector"
412415
},
@@ -443,6 +446,9 @@
443446
{
444447
"name": "R3ViewContainerRef"
445448
},
449+
{
450+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
451+
},
446452
{
447453
"name": "RadioControlRegistryModule"
448454
},
@@ -1451,9 +1457,6 @@
14511457
{
14521458
"name": "removeListItem2"
14531459
},
1454-
{
1455-
"name": "removeStyle"
1456-
},
14571460
{
14581461
"name": "removeValidators"
14591462
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@
398398
{
399399
"name": "NodeInjectorFactory"
400400
},
401+
{
402+
"name": "NoneEncapsulationDomRenderer"
403+
},
401404
{
402405
"name": "NullInjector"
403406
},
@@ -434,6 +437,9 @@
434437
{
435438
"name": "R3ViewContainerRef"
436439
},
440+
{
441+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
442+
},
437443
{
438444
"name": "REQUIRED_VALIDATOR"
439445
},
@@ -1415,9 +1421,6 @@
14151421
{
14161422
"name": "removeListItem"
14171423
},
1418-
{
1419-
"name": "removeStyle"
1420-
},
14211424
{
14221425
"name": "removeValidators"
14231426
},

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@
476476
{
477477
"name": "NodeInjectorFactory"
478478
},
479+
{
480+
"name": "NoneEncapsulationDomRenderer"
481+
},
479482
{
480483
"name": "NullInjector"
481484
},
@@ -533,6 +536,9 @@
533536
{
534537
"name": "R3ViewContainerRef"
535538
},
539+
{
540+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
541+
},
536542
{
537543
"name": "ROUTER_CONFIGURATION"
538544
},
@@ -1763,9 +1769,6 @@
17631769
{
17641770
"name": "removeFromArray"
17651771
},
1766-
{
1767-
"name": "removeStyle"
1768-
},
17691772
{
17701773
"name": "renderComponent"
17711774
},

packages/core/test/bundling/standalone_bootstrap/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@
269269
{
270270
"name": "NodeInjectorFactory"
271271
},
272+
{
273+
"name": "NoneEncapsulationDomRenderer"
274+
},
272275
{
273276
"name": "NullInjector"
274277
},
@@ -290,6 +293,9 @@
290293
{
291294
"name": "R3Injector"
292295
},
296+
{
297+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
298+
},
293299
{
294300
"name": "RefCountOperator"
295301
},
@@ -869,9 +875,6 @@
869875
{
870876
"name": "removeFromArray"
871877
},
872-
{
873-
"name": "removeStyle"
874-
},
875878
{
876879
"name": "renderComponent"
877880
},

packages/core/test/bundling/todo/bundle.golden_symbols.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@
311311
{
312312
"name": "NodeInjectorFactory"
313313
},
314+
{
315+
"name": "NoneEncapsulationDomRenderer"
316+
},
314317
{
315318
"name": "NullInjector"
316319
},
@@ -347,6 +350,9 @@
347350
{
348351
"name": "R3ViewContainerRef"
349352
},
353+
{
354+
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
355+
},
350356
{
351357
"name": "RefCountOperator"
352358
},
@@ -1211,9 +1217,6 @@
12111217
{
12121218
"name": "removeFromArray"
12131219
},
1214-
{
1215-
"name": "removeStyle"
1216-
},
12171220
{
12181221
"name": "renderComponent"
12191222
},

0 commit comments

Comments
 (0)