Skip to content

Commit

Permalink
fix(@nguniversal/common): correctly handle multiple lazy CSS files
Browse files Browse the repository at this point in the history
This commit fixes an issue with the regexp that caused incorrect output.

Closes #3128

(cherry picked from commit b603f35)
  • Loading branch information
alan-agius4 committed May 16, 2023
1 parent 07a29f4 commit 90d6939
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion integration/express-engine-ivy/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"styles": [
"src/styles.css",
{
"input": "src/styles-extra.css",
"inject": true,
"bundleName": "extra"
}
],
"scripts": []
},
"configurations": {
Expand Down
8 changes: 6 additions & 2 deletions integration/express-engine-ivy/e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ describe('Hello world E2E Tests', () => {
await browser.driver.get(browser.baseUrl);

// Test the contents from the server.
const styleTag = browser.driver.findElement(by.css('link[rel="stylesheet"]'));
expect(styleTag.getAttribute('media')).toMatch('all');
const linkTags = await browser.driver.findElements(by.css('link[rel="stylesheet"]'));
expect(linkTags.length).toBe(2);

for (const linkTag of linkTags) {
expect(linkTag.getAttribute('media')).toMatch('all');
}

// Make sure there were no client side errors.
verifyNoBrowserErrors();
Expand Down
4 changes: 4 additions & 0 deletions integration/express-engine-ivy/src/styles-extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* You can add global styles to this file, and also import other style files */
.foo {
background-color: blue;
}
2 changes: 1 addition & 1 deletion modules/common/engine/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class CommonEngine {
document: inlineCriticalCss
? // Workaround for https://github.com/GoogleChromeLabs/critters/issues/64
doc.replace(
/ media="print" onload="this\.media='.+'"(?: ngCspMedia=".+")?><noscript><link .+?><\/noscript>/g,
/ media="print" onload="this\.media='.+?'"(?: ngCspMedia=".+")?><noscript><link .+?><\/noscript>/g,
'>',
)
: doc,
Expand Down

0 comments on commit 90d6939

Please sign in to comment.