Skip to content

fix(@angular/build): prevent esbuild service hang on internal component stylesheet builds#33498

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix-ng-build-hang-33497
Open

fix(@angular/build): prevent esbuild service hang on internal component stylesheet builds#33498
clydin wants to merge 1 commit into
angular:mainfrom
clydin:fix-ng-build-hang-33497

Conversation

@clydin

@clydin clydin commented Jul 1, 2026

Copy link
Copy Markdown
Member

Switching to esbuild.context() + rebuild() for all builds in PR #33267 meant that all component stylesheet builds (which are separate BundlerContext instances) also created individual esbuild contexts. For builds with large amounts of stylesheets, this resulted in creating and concurrently disposing many esbuild contexts, leading to a timing deadlock/hang in the esbuild service child process.

This change adds an alwaysUseContext parameter (defaulting to false) to BundlerContext to allow the main/global bundle contexts to continue using esbuild.context() (to ensure their plugins' onDispose callbacks run), while allowing component stylesheets to safely fall back to one-shot esbuild.build() during non-incremental/one-shot builds.

@clydin clydin added the target: patch This PR is targeted for the next patch release label Jul 1, 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 introduces an alwaysUseContext flag to BundlerContext to force the use of an esbuild build context, while falling back to a single build for non-incremental paths. The review feedback suggests checking if the context is disposed before and after performing a single build to prevent executing builds on a disposed context. Additionally, it is recommended to reorder the constructor parameters of BundlerContext so that alwaysUseContext comes before the optional initialFilter parameter, which simplifies instantiation by avoiding the need to pass undefined multiple times.

Comment thread packages/angular/build/src/tools/esbuild/bundler-context.ts
Comment thread packages/angular/build/src/tools/esbuild/bundler-context.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
Comment thread packages/angular/build/src/builders/application/setup-bundling.ts Outdated
@clydin clydin force-pushed the fix-ng-build-hang-33497 branch from 6996d29 to 795037f Compare July 1, 2026 17:10
…nt stylesheet builds

Switching to esbuild.context() + rebuild() for all builds in PR angular#33267 meant that all component stylesheet builds (which are separate BundlerContext instances) also created individual esbuild contexts. For builds with large amounts of stylesheets, this resulted in creating and concurrently disposing many esbuild contexts, leading to a timing deadlock/hang in the esbuild service child process.

This change adds an alwaysUseContext parameter (defaulting to false) to BundlerContext to allow the main/global bundle contexts to continue using esbuild.context() (to ensure their plugins' onDispose callbacks run), while allowing component stylesheets to safely fall back to one-shot esbuild.build() during non-incremental/one-shot builds.
@clydin clydin force-pushed the fix-ng-build-hang-33497 branch from 795037f to 768cf13 Compare July 1, 2026 17:14
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jul 1, 2026
@clydin clydin requested a review from alan-agius4 July 1, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: patch This PR is targeted for the next patch release

1 participant