Skip to content

refactor(@angular/build): introduce AngularCompilationContext to manage compiler lifecycle#33437

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:refactor-compilation-context
Open

refactor(@angular/build): introduce AngularCompilationContext to manage compiler lifecycle#33437
clydin wants to merge 1 commit into
angular:mainfrom
clydin:refactor-compilation-context

Conversation

@clydin

@clydin clydin commented Jun 23, 2026

Copy link
Copy Markdown
Member

Refactors the ambient/global sharedTSCompilationState synchronization singleton into an explicit, orchestrator-instantiated AngularCompilationContext. This context encapsulates the AngularCompilation instance and its ready promise/resolver.

The context is instantiated once in executeBuild and passed down to both browser and server compiler plugins, eliminating global state and providing a single cohesive API to manage worker thread lifecycles via context.dispose().

@clydin clydin added the target: minor This PR is targeted for the next minor release label Jun 23, 2026
@clydin clydin force-pushed the refactor-compilation-context branch 2 times, most recently from 68f6337 to f0f31c2 Compare June 23, 2026 19:18
@clydin clydin marked this pull request as ready for review June 23, 2026 19:38

@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 Angular compilation state management by replacing the global SharedTSCompilationState with a localized AngularCompilationContext. This context wraps the AngularCompilation instance and manages its lifecycle, introducing a SecondaryCompilationContext to prevent secondary bundler contexts (such as polyfills or SSR entries) from prematurely disposing of the primary compilation worker. The review feedback highlights two important resource management improvements: wrapping the context setup in a try...catch block in execute-build.ts to prevent resource leaks if an error is thrown during initialization, and catching potential errors during compilation closure in compilation-state.ts to avoid unhandled promise rejections.

Comment thread packages/angular/build/src/builders/application/execute-build.ts Outdated
@clydin clydin force-pushed the refactor-compilation-context branch from f0f31c2 to 474683b Compare June 23, 2026 19:44
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 23, 2026
@clydin clydin requested a review from alan-agius4 June 23, 2026 20:03
@clydin clydin force-pushed the refactor-compilation-context branch from 474683b to d359f03 Compare June 23, 2026 21:02
…ge compiler lifecycle

Refactors the ambient/global sharedTSCompilationState synchronization singleton into an explicit, orchestrator-instantiated AngularCompilationContext. This context encapsulates the AngularCompilation instance and its ready promise/resolver.

The context is instantiated once in executeBuild and passed down to both browser and server compiler plugins, eliminating global state and providing a single cohesive API to manage worker thread lifecycles via context.dispose().
@clydin clydin force-pushed the refactor-compilation-context branch from d359f03 to 62a20f4 Compare June 23, 2026 21:35
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: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant