Skip to content

refactor(@angular/build): lazy load beasties in critical css processor - #33848

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/lazy-load-beasties
Open

refactor(@angular/build): lazy load beasties in critical css processor#33848
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/lazy-load-beasties

Conversation

@clydin

@clydin clydin commented Aug 12, 2026

Copy link
Copy Markdown
Member

Beasties and its transitive dependencies (postcss, css-select, htmlparser2, domutils, dom-serializer, and postcss parsers) were previously imported statically at the top level of the critical CSS utility.

This change converts beasties to a dynamic import that is resolved on first use within the process method of InlineCriticalCssProcessor. Deferring the loading of beasties eliminates synchronous module statting, file reading, and V8 bytecode parsing overhead from the initial CLI setup phase.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Aug 12, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the critical CSS inlining utility to dynamically import the beasties package, wrapping the BeastiesExtended class definition inside an asynchronous helper function to defer loading. Feedback on these changes highlights a potential runtime error: subclass field initializers (like warnings and errors) run after the super() constructor call. If the base class constructor triggers any logging during initialization, it will attempt to push to undefined arrays, resulting in a TypeError. To prevent this, it is recommended to use lazy-initialized getters for these arrays.

Comment thread packages/angular/build/src/utils/index-file/inline-critical-css.ts Outdated
Beasties and its transitive dependencies (postcss, css-select, htmlparser2, domutils, dom-serializer, and postcss parsers) were previously imported statically at the top level of the critical CSS utility.

This change converts beasties to a dynamic import that is resolved on first use within the process method of InlineCriticalCssProcessor. Deferring the loading of beasties eliminates synchronous module statting, file reading, and V8 bytecode parsing overhead from the initial CLI setup phase.
@clydin
clydin force-pushed the perf/lazy-load-beasties branch from 875ba0b to 6752f13 Compare August 12, 2026 19:29
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 12, 2026
@clydin
clydin requested a review from alan-agius4 August 12, 2026 21:06
@alan-agius4 alan-agius4 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 Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants