Skip to content

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

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix-ng-build-hang-33497
Jul 2, 2026
Merged

fix(@angular/build): prevent esbuild service hang on internal component stylesheet builds#33498
alan-agius4 merged 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
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed 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 labels Jul 2, 2026
@alan-agius4 alan-agius4 merged commit 6d9b360 into angular:main Jul 2, 2026
41 of 42 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

alan-agius4 added a commit to alan-agius4/ng-packagr that referenced this pull request Jul 2, 2026
… builds

Switching to esbuild.context() + rebuild() for all builds 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 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.

Cherry-picked from angular/angular-cli#33498
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