You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 02d9d84
Browse filesBrowse the repository at this point in the historyBrowse files
fix(@angular/ssr): handle handle load event for multiple stylesheets and CSP nonces
The `load` event for each stylesheet may not always be triggered by Google Chrome's handling. Refer to: https://crbug.com/1521256
This results in the media attribute persistently being set to print, leading to distorted styles in the UI. To address this issue, we substitute the onload logic by replacing `link.addEventListener('load', ...` with `document.documentElement.addEventListener('load', ...` and filtering for link tags.
Closes#26932
(cherry picked from commit eef1aa8)
* Script text used to change the media value of the link tags.
24
+
*
25
+
* NOTE:
26
+
* We do not use `document.querySelectorAll('link').forEach((s) => s.addEventListener('load', ...)`
27
+
* because this does not always fire on Chome.
28
+
* See: https://github.com/angular/angular-cli/issues/26932 and https://crbug.com/1521256
24
29
*/
25
30
constLINK_LOAD_SCRIPT_CONTENT=[
26
-
`(() => {`,
27
-
// Save the `children` in a variable since they're a live DOM node collection.
28
-
// We iterate over the direct descendants, instead of going through a `querySelectorAll`,
29
-
// because we know that the tags will be directly inside the `head`.
30
-
` const children = document.head.children;`,
31
-
// Declare `onLoad` outside the loop to avoid leaking memory.
32
-
// Can't be an arrow function, because we need `this` to refer to the DOM node.
33
-
` function onLoad() {this.media = this.getAttribute('${CSP_MEDIA_ATTR}');}`,
34
-
// Has to use a plain for loop, because some browsers don't support
35
-
// `forEach` on `children` which is a `HTMLCollection`.
0 commit comments