Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): error during critical CSS inlining for external stylesheets #25584

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

crisbeto
Copy link
Member

These changes revert the performance improvement from e88aea6 and add a test. The problem with the previous approach is that it assumes that a link tag processed by Critters will be preceded by a style tag that was inserted by Critters. This assumption might not necessarily be true if Critters is unable to resolve the content of the linked styles. Furthermore, I'm not sure if we need to optimize this code path to begin with, because it only does a shallow traversal of the head tag which is generally fast and is unlikely to have many direct descendants.

Fixes #25419.

…g for external stylesheets

These changes revert the performance improvement from angular@e88aea6 and add a test. The problem with the previous approach is that it assumes that a `link` tag processed by Critters will be preceded by a `style` tag that was inserted by Critters. This assumption might not necessarily be true if Critters is unable to resolve the content of the linked styles. Furthermore, I'm not sure if we need to optimize this code path to begin with, because it only does a shallow traversal of the `head` tag which is generally fast and is unlikely to have many direct descendants.

Fixes angular#25419.
@crisbeto crisbeto requested review from alan-agius4 and clydin July 26, 2023 07:37
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: @angular-devkit/build-angular labels Jul 26, 2023
@@ -146,7 +146,15 @@ class CrittersExtended extends Critters {
this.conditionallyInsertCspLoadingScript(document, cspNonce);
}

link.prev?.setAttribute('nonce', cspNonce);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could've kept this and checked that link.prev.tagName === 'style' but that'll be incorrect for a markup like this:

<head>
  <style></style>
  <link rel="stylesheet" href="https://some/external/style.css">
</head>

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 26, 2023
@clydin clydin merged commit d6ae2c7 into angular:main Jul 26, 2023
@vlio20
Copy link

vlio20 commented Aug 18, 2023

Hi @crisbeto , in what version this fix will be available?

@crisbeto
Copy link
Member Author

It should've been out in 16.1.6.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: @angular-devkit/build-angular target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error encountered when updating @angular-devkit/build-angular to Version 16.1.0
3 participants