Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@
},
"devDependencies": {
"@ampproject/remapping": "2.2.0",
"@angular/animations": "16.0.0-next.4",
"@angular/animations": "16.0.0-next.5",
"@angular/build-tooling": "https://github.com/angular/dev-infra-private-build-tooling-builds.git#4c7d40592a36f061c23dd08f437f734081f9979d",
"@angular/cdk": "15.2.4",
"@angular/common": "16.0.0-next.4",
"@angular/compiler": "16.0.0-next.4",
"@angular/compiler-cli": "16.0.0-next.4",
"@angular/core": "16.0.0-next.4",
"@angular/forms": "16.0.0-next.4",
"@angular/localize": "16.0.0-next.4",
"@angular/material": "15.2.4",
"@angular/cdk": "15.2.5",
"@angular/common": "16.0.0-next.5",
"@angular/compiler": "16.0.0-next.5",
"@angular/compiler-cli": "16.0.0-next.5",
"@angular/core": "16.0.0-next.5",
"@angular/forms": "16.0.0-next.5",
"@angular/localize": "16.0.0-next.5",
"@angular/material": "15.2.5",
"@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#052850d27f6c36226e1a62ab04af799746decd9a",
"@angular/platform-browser": "16.0.0-next.4",
"@angular/platform-browser-dynamic": "16.0.0-next.4",
"@angular/platform-server": "16.0.0-next.4",
"@angular/router": "16.0.0-next.4",
"@angular/service-worker": "16.0.0-next.4",
"@angular/platform-browser": "16.0.0-next.5",
"@angular/platform-browser-dynamic": "16.0.0-next.5",
"@angular/platform-server": "16.0.0-next.5",
"@angular/router": "16.0.0-next.5",
"@angular/service-worker": "16.0.0-next.5",
"@babel/core": "7.21.3",
"@babel/generator": "7.21.3",
"@babel/helper-annotate-as-pure": "7.18.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('AppShell Builder', () => {

expect(content).toContain('app-shell works!');
expect(content).toContain('<style nonce="{% nonce %}">p{color:#000}</style>');
expect(content).toContain('<style ng-app-id="ng" nonce="{% nonce %}">');
expect(content).toContain('<style nonce="{% nonce %}" ng-app-id="ng">');
expect(content).toContain('<app-root ngcspnonce="{% nonce %}"');
expect(content).toContain('<script nonce="{% nonce %}">');
expect(content).toMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Browser Builder lazy modules', () => {
const { files } = await browserBuild(architect, host, target);
expect(files['src_one_ts.js']).toBeDefined();
expect(files['src_two_ts.js']).toBeDefined();
expect(files['default-node_modules_angular_common_fesm2020_http_mjs.js']).toBeDefined();
expect(files['default-node_modules_angular_common_fesm2022_http_mjs.js']).toBeDefined();
});

it(`supports disabling the common bundle`, async () => {
Expand All @@ -165,6 +165,6 @@ describe('Browser Builder lazy modules', () => {
const { files } = await browserBuild(architect, host, target, { commonChunk: false });
expect(files['src_one_ts.js']).toBeDefined();
expect(files['src_two_ts.js']).toBeDefined();
expect(files['default-node_modules_angular_common_fesm2020_http_mjs.js']).toBeUndefined();
expect(files['default-node_modules_angular_common_fesm2022_http_mjs.js']).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ const MEDIA_SET_HANDLER_PATTERN = /^this\.media=["'](.*)["'];?$/;
*/
const CSP_MEDIA_ATTR = 'ngCspMedia';

/**
* Script text used to change the media value of the link tags.
*/
const LINK_LOAD_SCRIPT_CONTENT = [
`(() => {`,
// Save the `children` in a variable since they're a live DOM node collection.
// We iterate over the direct descendants, instead of going through a `querySelectorAll`,
// because we know that the tags will be directly inside the `head`.
` const children = document.head.children;`,
// Declare `onLoad` outside the loop to avoid leaking memory.
// Can't be an arrow function, because we need `this` to refer to the DOM node.
` function onLoad() {this.media = this.getAttribute('${CSP_MEDIA_ATTR}');}`,
// Has to use a plain for loop, because some browsers don't support
// `forEach` on `children` which is a `HTMLCollection`.
` for (let i = 0; i < children.length; i++) {`,
` const child = children[i];`,
` child.hasAttribute('${CSP_MEDIA_ATTR}') && child.addEventListener('load', onLoad);`,
` }`,
`})();`,
].join('\n');

export interface InlineCriticalCssProcessOptions {
outputPath: string;
}
Expand All @@ -40,6 +61,8 @@ interface PartialHTMLElement {
textContent: string;
tagName: string | null;
children: PartialHTMLElement[];
next: PartialHTMLElement | null;
prev: PartialHTMLElement | null;
}

/** Partial representation of an HTML `Document`. */
Expand Down Expand Up @@ -123,15 +146,7 @@ class CrittersExtended extends Critters {
this.conditionallyInsertCspLoadingScript(document, cspNonce);
}

// Ideally we would hook in at the time Critters inserts the `style` tags, but there isn't
// a way of doing that at the moment so we fall back to doing it any time a `link` tag is
// inserted. We mitigate it by only iterating the direct children of the `<head>` which
// should be pretty shallow.
document.head.children.forEach((child) => {
if (child.tagName === 'style' && !child.hasAttribute('nonce')) {
child.setAttribute('nonce', cspNonce);
}
});
link.prev?.setAttribute('nonce', cspNonce);
}

return returnValue;
Expand All @@ -142,7 +157,8 @@ class CrittersExtended extends Critters {
*/
private findCspNonce(document: PartialDocument): string | null {
if (this.documentNonces.has(document)) {
return this.documentNonces.get(document) ?? null;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.documentNonces.get(document)!;
}

// HTML attribute are case-insensitive, but the parser used by Critters is case-sensitive.
Expand All @@ -159,30 +175,14 @@ class CrittersExtended extends Critters {
* Inserts the `script` tag that swaps the critical CSS at runtime,
* if one hasn't been inserted into the document already.
*/
private conditionallyInsertCspLoadingScript(document: PartialDocument, nonce: string) {
private conditionallyInsertCspLoadingScript(document: PartialDocument, nonce: string): void {
if (this.addedCspScriptsDocuments.has(document)) {
return;
}

const script = document.createElement('script');
script.setAttribute('nonce', nonce);
script.textContent = [
`(() => {`,
// Save the `children` in a variable since they're a live DOM node collection.
// We iterate over the direct descendants, instead of going through a `querySelectorAll`,
// because we know that the tags will be directly inside the `head`.
` const children = document.head.children;`,
// Declare `onLoad` outside the loop to avoid leaking memory.
// Can't be an arrow function, because we need `this` to refer to the DOM node.
` function onLoad() {this.media = this.getAttribute('${CSP_MEDIA_ATTR}');}`,
// Has to use a plain for loop, because some browsers don't support
// `forEach` on `children` which is a `HTMLCollection`.
` for (let i = 0; i < children.length; i++) {`,
` const child = children[i];`,
` child.hasAttribute('${CSP_MEDIA_ATTR}') && child.addEventListener('load', onLoad);`,
` }`,
`})();`,
].join('\n');
script.textContent = LINK_LOAD_SCRIPT_CONTENT;
// Append the script to the head since it needs to
// run as early as possible, after the `link` tags.
document.head.appendChild(script);
Expand Down
4 changes: 2 additions & 2 deletions packages/ngtools/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
},
"devDependencies": {
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
"@angular/compiler": "16.0.0-next.4",
"@angular/compiler-cli": "16.0.0-next.4",
"@angular/compiler": "16.0.0-next.5",
"@angular/compiler-cli": "16.0.0-next.5",
"typescript": "~5.0.2",
"webpack": "5.76.2"
}
Expand Down
32 changes: 16 additions & 16 deletions tests/legacy-cli/e2e/ng-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
"description": "snapshot versions of Angular for e2e testing",
"private": true,
"dependencies": {
"@angular/animations": "github:angular/animations-builds#785ecac0e2daf780a0794447276bdbab65a09f77",
"@angular/cdk": "github:angular/cdk-builds#44433b54dca962b14c2ceebc4f9fe67041cc300a",
"@angular/common": "github:angular/common-builds#8208995cdf5411bdf5e7bc9e3906897d989e5bf7",
"@angular/compiler": "github:angular/compiler-builds#a59b327b94c409f29dd064eb1a36fdd808396a72",
"@angular/compiler-cli": "github:angular/compiler-cli-builds#8182056b90c15534959b81b93b93d144cb77136f",
"@angular/core": "github:angular/core-builds#a780c96941794b76688fc223aa6ee5c7b0da5b48",
"@angular/forms": "github:angular/forms-builds#13963272f13e6d86a88fa96753ca20af7e410fb8",
"@angular/language-service": "github:angular/language-service-builds#fdd7b72345c1230ccf35ee7e935bf29b3f46903a",
"@angular/localize": "github:angular/localize-builds#947ff4e052eac77058962e010337fb220fef4980",
"@angular/material": "github:angular/material-builds#effa135d9e6cf0df54d8b730a632d3d36dce5ef6",
"@angular/material-moment-adapter": "github:angular/material-moment-adapter-builds#19a89043547594c07f6ca74a2bdec95cdb7114e1",
"@angular/platform-browser": "github:angular/platform-browser-builds#f57dbf06108094ec0a977310586acbe6a4d1adaf",
"@angular/platform-browser-dynamic": "github:angular/platform-browser-dynamic-builds#50908d71ecee699edf2c12ed129b8c1843efe657",
"@angular/platform-server": "github:angular/platform-server-builds#59bfcf5645efefb80b7299e02adcb4980143faff",
"@angular/router": "github:angular/router-builds#cadfecb1a647291ed497bdd3c9826f3fff9e7287",
"@angular/service-worker": "github:angular/service-worker-builds#e15b7b6ae4083b2fd0f2fa34fea3c7988c6c6e9a"
"@angular/animations": "github:angular/animations-builds#e5814d8d180525e09df75dd6ddf1c5478c21243e",
"@angular/cdk": "github:angular/cdk-builds#127b43a3559f0d95c4abc6556e0f349b496a9bb2",
"@angular/common": "github:angular/common-builds#0c76816443b0ed7098e6ebf15477d1689700a73d",
"@angular/compiler": "github:angular/compiler-builds#7a69fea9169a95f5dd15bbdb794c659c32e794d5",
"@angular/compiler-cli": "github:angular/compiler-cli-builds#fd4e96f5a5ce7812e7730d7aaf21d7a90f7da080",
"@angular/core": "github:angular/core-builds#38de6517af8e16b3f68d057b2a4a30db005bdab5",
"@angular/forms": "github:angular/forms-builds#9d6090393f55a157417ef71c3582e5e502c8cad6",
"@angular/language-service": "github:angular/language-service-builds#241200c0768a8f9f35f3fc4a1e99898fe018e2cc",
"@angular/localize": "github:angular/localize-builds#52511c67e31c8fb711ef2ec64d034eb65a599622",
"@angular/material": "github:angular/material-builds#49fe77c7440c7126a160ec214f3f61b9122b1204",
"@angular/material-moment-adapter": "github:angular/material-moment-adapter-builds#e6bd3da5f793d663107ee024ff1c4e338dc2cb16",
"@angular/platform-browser": "github:angular/platform-browser-builds#fd7cfec6f8f00a83d6e0646656e4a3fa707ee71b",
"@angular/platform-browser-dynamic": "github:angular/platform-browser-dynamic-builds#e45ed8443ee0b6790ac18d54b496a26d6c845456",
"@angular/platform-server": "github:angular/platform-server-builds#76515884bca641c4dac339e2320410c96b3b0642",
"@angular/router": "github:angular/router-builds#4511211d1ccb93af9c90d81bccb58bce3e8fbc39",
"@angular/service-worker": "github:angular/service-worker-builds#fe9b98e0bc41afd292d715491580a0df4833e587"
}
}
Loading