Skip to content

Commit 49ad7c6

Browse files
alan-agius4kirjs
authored andcommitted
fix(core): use injected DOCUMENT for CSP_NONCE
This ensures that the right document is used and that `CSP_NONCE` can be used in `provideAppInitializer` and `provideEnvironmentInitializer`. Closes #65624 (cherry picked from commit 3b1fa82)
1 parent 8d3a89a commit 49ad7c6

File tree

7 files changed

+4
-8
lines changed

7 files changed

+4
-8
lines changed

packages/core/src/application/application_tokens.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {ENVIRONMENT_INITIALIZER, inject, StaticProvider} from '../di';
1010
import {InjectionToken} from '../di/injection_token';
11+
import {DOCUMENT} from '../document';
1112
import {RuntimeError, RuntimeErrorCode} from '../errors';
12-
import {getDocument} from '../render3/interfaces/document';
1313

1414
/**
1515
* A DI token representing a string ID, used
@@ -138,7 +138,9 @@ export const CSP_NONCE = new InjectionToken<string | null>(
138138
// 4. Have the `ComponentFactory` read the attribute and provide it to the injector under the
139139
// hood - has the same problem as #1 and #2 in that the renderer is used to query for the root
140140
// node and the nonce value needs to be available when the renderer is created.
141-
return getDocument().body?.querySelector('[ngCspNonce]')?.getAttribute('ngCspNonce') || null;
141+
return (
142+
inject(DOCUMENT).body?.querySelector('[ngCspNonce]')?.getAttribute('ngCspNonce') || null
143+
);
142144
},
143145
},
144146
);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@
494494
"getDOM",
495495
"getDeclarationTNode",
496496
"getDirectiveDef",
497-
"getDocument",
498497
"getElementDepthCount",
499498
"getFactoryDef",
500499
"getFirstLContainer",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@
440440
"getDeclarationTNode",
441441
"getDeferBlockDataIndex",
442442
"getDirectiveDef",
443-
"getDocument",
444443
"getElementDepthCount",
445444
"getFactoryDef",
446445
"getFirstLContainer",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@
558558
"getDOM",
559559
"getDeclarationTNode",
560560
"getDirectiveDef",
561-
"getDocument",
562561
"getElementDepthCount",
563562
"getFactoryDef",
564563
"getFactoryOf",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@
559559
"getDOM",
560560
"getDeclarationTNode",
561561
"getDirectiveDef",
562-
"getDocument",
563562
"getElementDepthCount",
564563
"getFactoryDef",
565564
"getFactoryOf",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@
649649
"getDataKeys",
650650
"getDeclarationTNode",
651651
"getDirectiveDef",
652-
"getDocument",
653652
"getElementDepthCount",
654653
"getFactoryDef",
655654
"getFactoryOf",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@
365365
"getDOM",
366366
"getDeclarationTNode",
367367
"getDirectiveDef",
368-
"getDocument",
369368
"getFactoryDef",
370369
"getFirstLContainer",
371370
"getGlobalLocale",

0 commit comments

Comments
 (0)