When an element with an `animate.leave` binding is detached,
`node_manipulation` eagerly records `{el, declarationView}` in the
module-level `leavingNodes` `WeakMap`. Previously, if `runLeaveAnimations`
resolved an empty class list (such as `''`, `[]`, `null`, or
`undefined`), it pushed a resolver and resolved immediately without
starting `animateLeaveClassRunner`, so `clearLeavingNodes` was never
called and every removed element and its declaration view remained
retained for the lifetime of the `TNode`.
Avoid registering a resolver or adding the view to `allLeavingAnimations`
when `activeClasses` is empty, and clear the tracked `leavingNodes` entry
from `node_animations` once leave animations settle (or when the
animation queue cannot be resolved). Clearing at settlement preserves
`leavingNodes` tracking and `declarationView` while composed or
descendant leave animations are still running, while keeping the cleanup
inside the tree-shaken animation runtime. Also delete empty `TNode`
entries from `leavingNodes` in `cancelLeavingNodes`.
Fixes#72141
Update `ToolDescriptor`, `declareExperimentalWebMcpTool`, and `provideExperimentalWebMcpTools` to explicitly support the `outputSchema` property. This allows tools to specify their expected return format using standard JSON Schema syntax, ensuring that AI agents know exactly how to interpret the tool execution results.
In `mergeWithExistingDefinition`, `directiveDefs` and `pipeDefs` were always
restored from `clone` to preserve remote scopes patched by
`ɵɵsetComponentScope` from an `NgModule` file, which does not re-run during HMR
of the component file.
Standalone components never use `ɵɵsetComponentScope` because their imports are
inlined directly onto the component definition (in `ngtsc`, `handler.ts` keeps
non-self dependencies during HMR and emits the component self-reference only
while used in the template). Always restoring `clone` left removed standalone
directives active, caused swapped or newly added standalone directives to fail
silently and pipes to throw `NG0302`, and broke recursive self-references.
Use `newDef.directiveDefs` and `newDef.pipeDefs` directly for standalone
components (including `null`), while keeping `clone.directiveDefs` and
`clone.pipeDefs` unconditionally for non-standalone components. Add DOM-level
acceptance specs in `hmr_spec.ts`.
In `getParentBlockHydrationQueue`, PR #58722 breaks out of the ancestor loop
before calling `hydrationQueue.unshift(currentBlockId)` when it encounters an
ancestor `@defer` block that is already hydrating. Because of that,
`hydrationQueue` never contains the hydrating ancestor, only the unhydrated
descendants below it.
`triggerHydrationFromBlockName` still contains a `hydrationQueue.shift()` added
in PR #60203 under the assumption that the hydrating parent sat at index 0.
When `parentBlockPromise` is non-null, that shifts off the first unhydrated
child block instead: in a 2-level nested `@defer` block it empties the queue
and drops the replay event, and in a 3-level hierarchy (immediate inside
interaction inside immediate) it drops the middle block so both inner blocks
stay dehydrated.
Remove the stale `hydrationQueue.shift()` call and add regression specs in
`incremental_hydration_spec.ts`.
Previously, GenericKeyFn.keyOf() wrapped string literals and quoted object literal keys in double quotes without length-prefixing or escaping. As a result, distinct array or object literals extracted during the template compiler's pure function optimization phase (such as ['a', 'b'] and ['a","b'], or {'a': 1, 'b': 2} and {'a":1,"b': 2}) produced identical constant pool keys and erroneously shared the same constant factory.
Prefix string literals and quoted object literal keys with their length ("<length>:<value>") in GenericKeyFn.keyOf() so embedded quotes and delimiters cannot cause key collisions without needing to scan or escape the string.
Fixes#71914
Consider the following example:
```ts
@Component({
template: '@for (item of items; track item) {{{ item }}}',
})
class App {
items = {0: 'a', 1: 'b'};
}
```
Prior to this commit, `reconcile()` treated every non-nullish value that is
not an array as an iterable and called `Symbol.iterator` on it without a
check. A plain object therefore failed with a raw `TypeError`:
```
TypeError: t[Symbol.iterator] is not a function
```
That error carries no code, does not mention `@for`, and does not say which
template produced it. In a production build the stack is minified, so error
reporting shows nothing actionable. The same value through `*ngFor` reports
NG02200, which names the problem and suggests the keyvalue pipe, so `@for`
was harder to debug than the API it replaces.
With this commit the same value throws NG0957. Only the message text is
behind `ngDevMode`; the check itself is not, because production is where the
raw error is unreadable today. The array fast path is untouched, and `null`
and `undefined` keep rendering nothing.
The code is negative, which is how this package marks codes that have a
guide on angular.dev, so the fix ships with one.
Translated attributes with interpolations in a URL context (e.g.
`<a i18n-href href="{{url}}">` or an `href` inside an ICU case) were
sanitized with the raw `_sanitizeUrl` function, which ignores a
`Sanitizer` provided by the application. All other security contexts
already go through the `ɵɵsanitize*` instructions, as does the
compile-time path for static i18n attributes.
Use `ɵɵsanitizeUrl` for the URL context as well, so a custom
`Sanitizer` is consulted consistently.
`getInputsTypeExpression` in `@angular/compiler` emits `'alias'`, `'required'`, and `'isSignal'` as quoted string-literal property signatures in the `InputMap` type argument of `ɵɵDirectiveDeclaration` and `ɵɵComponentDeclaration` on `ɵdir` and `ɵcmp`. However, `ɵɵDirectiveDeclaration` and `ɵɵComponentDeclaration` in `@angular/core` declared those constraint keys as unquoted identifier property signatures (`{alias: string | null; required: boolean; isSignal?: boolean}`).
In standard TypeScript, quoted and unquoted property signatures are structurally identical. When a property-renaming safety pass rewrites unquoted identifier property signatures in `.d.ts` type literals while preserving quoted string-literal keys, the renamed constraint keys on `InputMap` no longer match the quoted `'alias'`, `'required'`, and `'isSignal'` keys emitted on preprocessed `ɵdir` and `ɵcmp` source declarations, failing `TS2344`.
Quote `'alias'`, `'required'`, and `'isSignal'` in the `InputMap` constraint on `ɵɵDirectiveDeclaration` and `ɵɵComponentDeclaration` so the declaration constraints match the quoted keys emitted by `@angular/compiler`.
Given this template:
```html
<main>
<span>{{ value }}</span>
</main>
```
During hydration, Angular looks for the text node that the server rendered
inside the `<span>`. If the HTML from the server was changed and this text
node is missing, dev mode throws a clear NG0500 error. But this check only
runs in dev mode.
Prior to this fix, production continued with the missing text node and failed
on the first update of that binding with a raw error that doesn't say what
went wrong:
```
TypeError: Cannot set properties of null (setting 'nodeValue')
```
With this fix, production throws NG0512 during hydration instead.
Note that static text behaves differently. Nothing ever updates it, so it
hydrated without an error before this fix and left a gap in the DOM. It now
throws as well.
Consider the following template:
```html
<main>
@if (show) {
<span>text</span>
}
</main>
```
During hydration, Angular looks for the comment node that marks where the
`@if` block (or an `<ng-container>`) is. If the HTML from the server was
changed and this comment is missing, dev mode throws a clear NG0502 error.
But this check only runs in dev mode.
Prior to this fix, production continued with the missing comment and failed
later with a raw error that doesn't say what went wrong:
```
TypeError: Cannot set properties of null (setting '__ngContext__')
```
With this fix, production also throws NG0502.
When running component tests in TestBed, an application may include
provideClientHydration() (e.g. from appConfig.providers) or use
defer blocks with hydrate triggers without hydration providers configured.
In these testing scenarios, there is no serialized server state in
TransferState. As a result, Angular emitted spurious warnings:
- NG0505: warning that client hydration was requested but no serialized info was found.
- NG0508: warning that incremental hydration is not enabled for @defer hydrate triggers.
This commit introduces an internal IS_TESTING token, provided by TestBedCompiler
and BrowserTestingModule, which suppresses these warnings in test environments.
Fixes#62053
This came up while updating Components to the 22.3 release candidate. We were reading `ngServerMode` directly which caused a reference error in some of our tests, because we weren't defining it globally. These changes guard `ngServerMode` and `ngDevMode` just in case.
Custom control (`value` or `checked` model, no ControlValueAccessor) bound with NgModel,
FormControlDirective or FormControlName is set up by setupCustomControl, which doesnt call
setUpValidators. Validator directives on element (required, minlength, any directive providing
NG_VALIDATORS) and NG_VALIDATORS provided by control itself never reach FormControl, so control
stays valid and form submits. ControlValueAccessor path merges them, and cleanUpControl already
removes them when FormControlDirective or FormControlName lets go of control
Call setUpValidators from setupCustomControl. Applying validators needs few more changes:
- FormControlName: ɵngControlUpdate runs before ngOnChanges of element, so setting control up
there would run control's own NG_VALIDATORS before its ngOnInit, and first ngOnChanges of each
validator directive would emit valueChanges and statusChanges during first change detection.
ɵngControlUpdate now only resolves control and ngOnChanges sets it up, same as for
ControlValueAccessor
- required: with FormControlDirective and FormControlName, NgControl also wrote `required` into
RequiredValidator on same element. That cleared static `required`, and Validators.required
turned into directive validator that outlived removeValidators(). setInputOnDirectives now
passes directive to writePredicate and NgControl skips RequiredValidator. Custom control gets
`required` from enabled RequiredValidator or Validators.required under all three directives
- errors: status inputs are read through untracked getters and `errors` was plain field, so
re-validation later in same pass (validator directive's ngOnChanges) left `invalid` and `errors`
stale, and markForCheck during that refresh doesnt re-run view. `errors` is backed by signal now
like `status`, and ngControlUpdate reads both, so errors-only change is bound in same pass, with
`emitEvent: false` too
- _enabled on validator directives is backed by signal too, so change from their ngOnChanges
reaches custom control in same change detection
Fixes#70721
Co-authored-by: leonsenft <[email protected]>
Standalone is the default, so the explicit flag is redundant. Remove the
occurrences added to core, platform-browser, forms and router tests since
the last cleanup.
`@mcp-b/webmcp-polyfill` is deprecated in favor of `@w3c/webmcp-polyfill`.
However, the latter doesn't include any testing utilities, just an install
API without a convenient way to reset the polyfill.
This change drops `@mcp-b/webmcp-polyfill` in favor of a lean `ModelContext`
mock used for the purposes of the `webmcp` tests.
Resolves several V8 closure-context and reference retention issues
across `@angular/core`, including isolating closure scopes in
`injectAsync`, `ɵɵboundaryUpdate`, and incremental hydration triggers,
skipping non-`jsaction` elements in event replay stashing, clearing
recovered signal error references, and avoiding retaining the document
reference in `InertDocumentHelper`.
Removes the unfinished prototype for signal-based components and directives
(the internal `signals: true` decorator flag):
* `@Directive`/`@Component` no longer accept the internal `signals` option.
* The compiler no longer reads it (ngtsc, JIT, linker, hybrid preprocessor)
and no longer emits `signals: true` in definitions, `isSignal: true` in
partial declarations, or the trailing `IsSignal` type argument of
`ɵɵDirectiveDeclaration`/`ɵɵComponentDeclaration`.
* The runtime drops `DirectiveDef.signals`/`ComponentDef.signals`,
`LViewFlags.SignalView` and the internal `ComponentMirror.isSignal`.
Signal inputs, model inputs and signal queries (input/query-level `isSignal`)
are unaffected.
Removes the experimental "selectorless" template syntax (`<MyComp>` / `@Dir(...)`)
which was never shipped. This deletes:
- compiler: lexer/parser support for component and directive tokens, the
html `Component`/`Directive` nodes and the R3 `Component`/`Directive`
(`TmplAstComponent`/`TmplAstDirective`) nodes together with their visitor
methods and the `directives` field on elements/templates, the
`selectorlessEnabled`/`enableSelectorless` parse options, direct pipe
references (`BindingPipeType`), selectorless reference validation, the
selectorless paths in the binder (`referencedDirectiveExists`),
type-check ops, indexer, i18n and template pipeline.
- compiler-cli: the `_enableSelectorless` option, selectorless component
analysis and `SelectorlessScope`, deferred selectorless dependencies,
selectorless template symbols, out-of-band diagnostics and the related
error codes (2024, 2025, 2026, 8018), the linker option, and the
preprocessor/ng-analyze selectorless analysis.
- language-service: selectorless definitions, quick info, references and
rename.
- the selectorless runtime and compiler tests.
`SelectorlessMatcher` is kept since it is used to match foreign components
(`foreignImports`) by tag name.
Cancel previous loads before returning for unavailable or errored resource
params. These transitions otherwise leave the old AbortSignal active and
keep its pending task blocking application stability.
Preserve pending-task ownership when cancelled promises settle after a new
request starts. Cover unavailable params, propagated statuses and errors,
and late resolution or rejection in regression tests.
Binding `null` or `undefined` to a resource URL property such as
`<iframe [src]>` throws NG0904 ("unsafe value used in a resource URL
context"), even though there is nothing unsafe about clearing the binding.
The inlined `ɵɵsanitizeResourceUrl` only accepts values marked trusted with
`bypassSecurityTrustResourceUrl` and rejects everything else, including
nullish values. This forces users to bind a trusted placeholder such as
`about:blank` instead of simply using `undefined`.
The same binding already works when a custom `Sanitizer` is provided,
because `DomSanitizer.sanitize` returns `null` for nullish values, which is
then mapped to an empty string. Apply the same handling to the inlined
sanitizer: `null` and `undefined` are mapped to an empty string, which the
browser treats as `about:blank` for `<iframe src>`. Since
`setElementAttribute` runs the sanitizer before removing an attribute for a
nullish value, this also fixes `[attr.src]` bindings on resource URL
attributes.
Fixes#42527
Introduces error boundary support in the Angular Router, allowing individual routes to declare an `errorComponent` and applications to configure global fallback defaults via `withErrorBoundaries`.
`triggerHydrationForBlockQueue` accessed `blocksBeingHydrated.get(dehydratedBlockId)` with a non-null assertion `!.resolve()`. If the entry was cleaned up while the function was suspended awaiting resource loading or next render, this resulted in an unhandled `TypeError: Cannot read properties of undefined (reading 'resolve')`.
Additionally, the pending task added by `pendingTasks.add()` was not guarded by a `try/finally`, causing the task to leak and permanently breaking application stability whenever hydration encountered an error or threw an exception.
This commit optional-chains `.resolve()` matching sibling accesses and wraps the queue processing loop in `try/finally` so `pendingTasks.remove(taskId)` is always invoked.
Fixes#71769