Commit 02d5e8d
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 #482981 parent f3f1399 commit 02d5e8d
File tree
18 files changed
+446
-154
lines changed- goldens
- public-api/platform-browser
- size-tracking
- packages
- core/test
- bundling
- animations
- cyclic_import
- forms_reactive
- forms_template_driven
- router
- standalone_bootstrap
- todo
- render3
- platform-browser
- src
- dom
- test/dom
- platform-server/src
18 files changed
+446
-154
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
401 | 401 | | |
402 | 402 | | |
403 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
404 | 407 | | |
405 | 408 | | |
406 | 409 | | |
| |||
440 | 443 | | |
441 | 444 | | |
442 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
443 | 449 | | |
444 | 450 | | |
445 | 451 | | |
| |||
1310 | 1316 | | |
1311 | 1317 | | |
1312 | 1318 | | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | 1319 | | |
1317 | 1320 | | |
1318 | 1321 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
299 | 302 | | |
300 | 303 | | |
301 | 304 | | |
| |||
320 | 323 | | |
321 | 324 | | |
322 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
323 | 329 | | |
324 | 330 | | |
325 | 331 | | |
| |||
998 | 1004 | | |
999 | 1005 | | |
1000 | 1006 | | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | 1007 | | |
1005 | 1008 | | |
1006 | 1009 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
410 | 413 | | |
411 | 414 | | |
412 | 415 | | |
| |||
443 | 446 | | |
444 | 447 | | |
445 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
446 | 452 | | |
447 | 453 | | |
448 | 454 | | |
| |||
1451 | 1457 | | |
1452 | 1458 | | |
1453 | 1459 | | |
1454 | | - | |
1455 | | - | |
1456 | | - | |
1457 | 1460 | | |
1458 | 1461 | | |
1459 | 1462 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
401 | 404 | | |
402 | 405 | | |
403 | 406 | | |
| |||
434 | 437 | | |
435 | 438 | | |
436 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
437 | 443 | | |
438 | 444 | | |
439 | 445 | | |
| |||
1415 | 1421 | | |
1416 | 1422 | | |
1417 | 1423 | | |
1418 | | - | |
1419 | | - | |
1420 | | - | |
1421 | 1424 | | |
1422 | 1425 | | |
1423 | 1426 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
479 | 482 | | |
480 | 483 | | |
481 | 484 | | |
| |||
533 | 536 | | |
534 | 537 | | |
535 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
536 | 542 | | |
537 | 543 | | |
538 | 544 | | |
| |||
1763 | 1769 | | |
1764 | 1770 | | |
1765 | 1771 | | |
1766 | | - | |
1767 | | - | |
1768 | | - | |
1769 | 1772 | | |
1770 | 1773 | | |
1771 | 1774 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
272 | 275 | | |
273 | 276 | | |
274 | 277 | | |
| |||
290 | 293 | | |
291 | 294 | | |
292 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
293 | 299 | | |
294 | 300 | | |
295 | 301 | | |
| |||
869 | 875 | | |
870 | 876 | | |
871 | 877 | | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | 878 | | |
876 | 879 | | |
877 | 880 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
314 | 317 | | |
315 | 318 | | |
316 | 319 | | |
| |||
347 | 350 | | |
348 | 351 | | |
349 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
350 | 356 | | |
351 | 357 | | |
352 | 358 | | |
| |||
1211 | 1217 | | |
1212 | 1218 | | |
1213 | 1219 | | |
1214 | | - | |
1215 | | - | |
1216 | | - | |
1217 | 1220 | | |
1218 | 1221 | | |
1219 | 1222 | | |
| |||
0 commit comments