Skip to content

Commit

Permalink
fix(multiple): set nonce using setAttribute (#28800)
Browse files Browse the repository at this point in the history
Uses `setAttribute` to set the nonce, instead of DOM property in order to work properly in SSR.

Fixes #28780.

(cherry picked from commit 452cde2)
  • Loading branch information
crisbeto committed Apr 1, 2024
1 parent 7ccc392 commit 6b5b0c5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cdk-experimental/column-resize/resize-strategy.ts
Expand Up @@ -238,7 +238,7 @@ export class CdkFlexTableResizeStrategy extends ResizeStrategy implements OnDest
this._styleElement = this._document.createElement('style');

if (this._nonce) {
this._styleElement.nonce = this._nonce;
this._styleElement.setAttribute('nonce', this._nonce);
}

this._styleElement.appendChild(this._document.createTextNode(''));
Expand Down
Expand Up @@ -118,7 +118,7 @@ export class CdkTableScrollContainer implements StickyPositioningListener, OnDes
this._styleElement = this._document.createElement('style');

if (this._nonce) {
this._styleElement.nonce = this._nonce;
this._styleElement.setAttribute('nonce', this._nonce);
}

this._styleRoot.appendChild(this._styleElement);
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/layout/media-matcher.ts
Expand Up @@ -65,7 +65,7 @@ function createEmptyStyleRule(query: string, nonce: string | undefined | null) {
mediaQueryStyleNode = document.createElement('style');

if (nonce) {
mediaQueryStyleNode.nonce = nonce;
mediaQueryStyleNode.setAttribute('nonce', nonce);
}

mediaQueryStyleNode.setAttribute('type', 'text/css');
Expand Down
2 changes: 1 addition & 1 deletion src/youtube-player/youtube-player.ts
Expand Up @@ -719,7 +719,7 @@ function loadApi(nonce: string | null): void {
script.async = true;

if (nonce) {
script.nonce = nonce;
script.setAttribute('nonce', nonce);
}

// Set this immediately to true so we don't start loading another script
Expand Down

0 comments on commit 6b5b0c5

Please sign in to comment.