Skip to content

feat(core): introduce @boundary control flow and programmatic error handling - #70463

Draft
JeanMeche wants to merge 6 commits into
angular:mainfrom
JeanMeche:error-boundary
Draft

feat(core): introduce @boundary control flow and programmatic error handling#70463
JeanMeche wants to merge 6 commits into
angular:mainfrom
JeanMeche:error-boundary

Conversation

@JeanMeche

@JeanMeche JeanMeche commented Aug 29, 2026

Copy link
Copy Markdown
Member

Introduces a declarative way to catch rendering errors in templates using the new @boundary block, preventing local failures from crashing the entire application hierarchy.

@boundary {
  <complex-chart [data]="data" />
} @error (let err = $error; let r = $retry) {
  <p>Failed to load chart: {{err.message}}</p>
  <button (click)="r()">Retry</button>
}

Additionally, this adds programmatic error handling for dynamically created views by introducing an onError option to ViewContainerRef.createComponent,createEmbeddedView and the standalone alone createComponent function:

viewContainerRef.createComponent(DynamicComponent, {
  onError: (err: Error, details: ErrorDetails) => {
    console.error('Component rendering failed:', err);
    // Render an alternative UI or log metrics
  }
});

Additional changes:

  • ErrorHandler can now implement onViewError(err, details) to receive rich metadata about caught boundary errors.

Note: most of design & implementation was done by @alxhub.
Note2: Docs on the feature will be addressed in a follow-up PR.

@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime area: server Issues related to server-side rendering area: language-service Issues related to Angular's VS Code language service labels Aug 29, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 29, 2026
alxhub and others added 2 commits August 29, 2026 02:36
Implement error interception during refreshView and provide onError callback options in ViewContainerRef for programmatic rendering and encapsulation of boundary errors.
Add the runtime primitives `ɵɵboundaryCreate` and `ɵɵboundaryUpdate` to
the core instructions, which handle synchronous view destruction and
provide the `ON_ERROR` interceptor hooks.

Also include the initial compiler AST representations for the new syntax
including the Lexer tokenization and HTML Parser integration. This lays
the foundational structure for `@boundary` prior to code generation.

Co-authored-by: Matthieu Riegler <kyro38@gmail.com>
@JeanMeche
JeanMeche force-pushed the error-boundary branch 2 times, most recently from 5ec5d86 to 2a70304 Compare August 29, 2026 00:45
alxhub and others added 4 commits August 29, 2026 02:51
Add support for `@boundary` blocks in the template type-checking pipeline.
Add support for the new `@boundary` and `@error` control flow blocks in the Angular Language Service.

This includes:
- Updating outlining spans to handle boundary blocks correctly.
- Adding classification visitor methods for semantic tokens.
- Adding template target visitor methods for navigation and hover support.
- Updating the TextMate grammar to recognize `@boundary` and the `when` clause.
…ation

Added some tests to ensure error boundaries work with SSR and hydration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime area: language-service Issues related to Angular's VS Code language service area: server Issues related to server-side rendering detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants