Commit graph

3757 commits

Author SHA1 Message Date
Miles Malerba
ebae211add feat(forms): introduce parse errors in signal forms
Parse errors allow a custom control to communicate that it is currently
unable to produce a valid value.

Parse errors are reported by implementing the optional `parseErrors`
property on the `FormUiControl`. The property should be a signal of the
current parse errors.

Also renames several `*Field` types to `*FieldTree`. This aligns with the new naming of the concept after `Field` was renamed
to `FieldTree`.
2026-01-22 22:19:10 +00:00
hawkgs
92d2498910 feat(core): add host node to DeferBlockData (#66546)
Add the host/container comment node to the `DeferBlockData`. This node can be used as a `@defer` block locator in the DOM tree in the absence of root nodes.

PR Close #66546
2026-01-20 18:16:32 +00:00
SkyZeroZx
95c386469c feat(forms): Add passing focus options to form field
Extends the `focus` method of form fields and custom controls to accept and propagate `FocusOptions`.

This enables developers to control focus behavior more precisely, for example, preventing scrolling when focusing an element.
2026-01-16 13:24:27 -08:00
Kristiyan Kostadinov
4831a9f676 fix(core): handle Set in class bindings
Currently migrating from `[ngClass]` to `[class]` isn't entirely supported, because `[ngClass]` supports `Set` values while `[class]` ignores them.

These changes add a bit of logic to bring them closer together and make the migration easier.
2026-01-15 13:39:59 -08:00
Miles Malerba
5974cd0afc
feat(forms): Ability to manually register a form field binding in signal forms
This PR adds the ability to manually register a binding with the
`FormField` directive. This is useful for a lower-level implementation
that takes the field tree as an `input()` rather than relying on the
automatic binding from `FormUiControl`.
2026-01-15 11:03:28 -08:00
Jessica Janiuk
e673eb6df2 Revert "refactor(core): remove ng when invoking enableProdMode"
This reverts commit cb5879f566.
2026-01-14 08:08:58 -08:00
Matthieu Riegler
cb5879f566 refactor(core): remove ng when invoking enableProdMode
This was caught while investigating a leak.
2026-01-13 11:39:48 -08:00
Jeremy Elbourn
871fa1b2dd docs: update OnChanges API reference w/ signal input
We had some reports of LLMs claiming that `ngOnChanges` does not include
changes for signal-based inputs. This is wrong (and the LLMs just made
it up), but we can update the docs at least to demonstrate `ngOnChanges`
with signal-based inputs.

Previously, the API reference used a real test as a code example, but
updating the test to a signal-based input is more involved than this
change needs to call for.
2026-01-13 09:04:24 -08:00
Alex Rickabaugh
1ba9b7ac50 feat(core): resource composition via snapshots
* Define `ResourceSnapshot<T>` as a type union of possible states for a
`Resource<T>`.
* Add `Resource.snapshot()` to convert a `Resource` to a signal of its
  snapshot.
* Add `resourceFromSnapshots` to convert a reactive snapshot back into a
  `Resource`.

By converting resources from/to `Signal<ResourceSnapshot>`s, full
composition of resources is now possible on top of signal composition APIs
like `computed` and `linkedSignal`.

For example, a common feature request is to have a `Resource` which retains
its value when its reactive source (params) changes. This can now be built
as a utility, leveraging `linkedSignal`'s previous value capability:

```ts
function withPreviousValue<T>(input: Resource<T>): Resource<T> {
  const derived = linkedSignal({
    source: input.snapshot,
    computation: (snap, previous) => {
      if (snap.status === 'loading' && previous?.value) {
        // When the input resource enters loading state, we keep the value
        // from its previous state, if any.
        return {status: 'loading', value: previous.value.value};
      }

      // Otherwise we simply forward the state of the input resource.
      return snap;
    },
  });

  return resourceFromSnapshots(derived);
}

// In application code:

userId = input.required<number>();
user = withPreviousValue(httpResource(() => `/user/{this.userId()}`));
// if `userId()` switches, `user.value()` will keep the old value until
// the new one is ready!
```
2026-01-12 13:49:56 -08:00
SkyZeroZx
fa6e82b569 refactor(core): Add missing OnDestroy to zone and zoneless change detection schedulers
Implements the OnDestroy interface in NgZoneChangeDetectionScheduler and ChangeDetectionSchedulerImpl
2026-01-12 10:00:24 -08:00
Miles Malerba
10e9022a07 feat(forms): allow focusing bound control from field state
Allows focusing the assocated bound control from the `FieldState`.
2026-01-12 09:59:42 -08:00
SkyZeroZx
f4469ad583 refactor(core): update error message links to versioned docs (#66374)
Error message links now point to the archived documentation site (v*.angular.dev)
so that referenced content matches the framework version in use.

See angular#44650

PR Close #66374
2026-01-09 22:33:51 +00:00
Miles Malerba
5671f2cc07
fix(forms): Rename signal form [field] to [formField]
This completes the rename started in #66136. `[field]` is too generic of
a selector for the forms system to own, and likely to cause naming
collisions with existing components. Therefore it is being renamed to
`[formField]`
2026-01-09 14:33:09 -08:00
Kristiyan Kostadinov
4cf1a92288 refactor(compiler): rework arrow function storage
Reworks how we store arrow functions in the following ways:
1. Rather than the `storeCallback` and `getCallback` instructions, we generate a single `arrowFunction` instruction.
2. The `arrowFunction` instruction uses a factory to create a new instance of the function when a function is read for the first time.
3. We now keep arrow functions in listeners in line so that they have access to `$event`.
2026-01-09 10:35:37 -08:00
Kristiyan Kostadinov
17733b70a3 refactor(core): add instructions for callback storage and retrieval
Adds the `ɵɵstoreCallback` instruction that allows for a callback to be stored for later usage, as well as `ɵɵgetCallback` which can be used to retrieve it.
2026-01-09 10:35:37 -08:00
cexbrayat
bb0dc8c4e0 refactor(core): typo in stability debugging warning message
untility -> utility
2026-01-07 14:44:06 -08:00
Jaime Burgos
5c75d29fb4
refactor(core): Improve tree-shakable RuntimeError error for INVALID_FIELD_DIRECTIVE_HOST
Improves the tree-shakable runtime error handling for `INVALID_FIELD_DIRECTIVE_HOST`.
2026-01-07 14:32:25 -08:00
Jessica Janiuk
30e9c62bdf fix(core): fix memory leak with event replay
This ensures event replay does not hold on to elements after an application has been destroyed.

fixes: #59261
2026-01-07 14:27:44 -08:00
Kristiyan Kostadinov
4dc5ae54a9 refactor(core): remove unused instruction parameter
The `thisArg` in pure functions isn't used so we can drop it. We still need to keep it on the underlying implementation, because pipe instructions rely on it.
2026-01-07 15:05:20 -05:00
Kristiyan Kostadinov
80b0fbba1f fix(core): avoid leaking view data in animations
The animations code currently tracks which views have running leave animations by adding them to a `Set`. This can leak memory if we don't clean something up on time.

These changes switch to tracking the views by their ID which doesn't risk retaining the view.

Fixes #66255.
2026-01-07 12:39:00 -05:00
hawkgs
51ed487fae docs(core): fix Ivy view data docs tables
The current formatting prevents the tables to be rendered making it hard to read them.
2026-01-07 09:22:43 -05:00
Miles Malerba
2d85ae5811 feat(forms): add [formField] directive
This will replace the `[field]` directive, since `[field]` is a very
generic name for signal forms to commandeer

refactor(forms): hook up `formField` directive in compiler

Hooks up the `formField` direcive to get the same treatment as the
`field` directive in the compiler.

apply updated formatting
2026-01-06 17:21:06 -05:00
Alan Agius
91dc91bae4
fix(core): sanitize sensitive attributes on SVG script elements
This commit updates the DOM security schema and sanitization logic to properly recognize and sanitize `href` and `xlink:href` attributes on SVG `<script>` elements.
2026-01-06 15:49:52 -05:00
Leon Senft
82a2de201f refactor(forms): bind native properties on interop controls
The framework will now bind all field state properties to their
corresponding native properties (if any) on interop form controls (those
using `ControlValueAccessor`), excluding those handled explicitly by
`ControlValueAccessor` such as `disabled`.
2026-01-06 13:12:17 -05:00
Leon Senft
15bddbdcda refactor(forms): bind field properties to all directives on interop controls
The framework will now bind the field state properties to all matching
directive inputs on form controls using Reactive Forms'
`ControlValueAccessor`.
2026-01-06 13:12:17 -05:00
Leon Senft
0c8f15d546 refactor(forms): bind field properties to all directives on custom controls
The framework will now bind the field state properties to all matching
directive inputs on custom form controls.
2026-01-06 13:12:17 -05:00
Leon Senft
c149f47ef6 refactor(forms): bind field properties to all directives on native controls
Since the `Field` directive manages binding `FieldState` properties to
the underlying form control automatically, the type checker prohibits
explicit bindings to the same properties to avoid conflicts. This proved
problematic in cases where developers wanted to bind these properties to
the inputs of other directives on form controls. Now the framework will
bind the field state properties to all matching directive inputs on
native controls.

Fix #65617
2026-01-06 13:12:17 -05:00
SkyZeroZx
1532be9d00 refactor(core): introduce tree-shakeable runtime error codes for NgModule handling and ViewContainerRef errors
Adds new tree-shakeable runtime error codes to improve error reporting for
NgModule resolution issues (duplicate or missing IDs) and invalid ViewContainerRef
operations involving destroyed views.
2026-01-05 16:52:24 -05:00
SkyZeroZx
b735c45974 docs: update tsDoc code examples to use TypeScript syntax highlighting 2026-01-05 12:31:44 -05:00
SkyZeroZx
fa430bffb0 docs: add @see links to API docs for better discoverability 2026-01-05 12:12:24 -05:00
Kristiyan Kostadinov
1765ebe79b Revert "refactor(core): Add ngDevMode guards and new sanitization error codes"
This reverts commit 4e7e38c591.
2026-01-02 11:37:24 +01:00
SkyZeroZx
02e80b4ea2 refactor(core): implement missing OnDestroy for schedulers
Implements the missing OnDestroy interface. Also removes an unused generic from a performance logging function.
2026-01-02 08:19:57 +01:00
SkyZeroZx
93fe833088 refactor(core): remove unused Injector and Renderer2 dependencies from hydration functions
Removes the unsued `Injector` & `Renderer2` dependency from the hydration annotation process.
2026-01-02 08:11:16 +01:00
Leon Senft
cb09fb8308 fix(forms): support custom controls with non signal-based models
* Recognize directives with non signal-based models as valid custom controls
* Relax type checker to allow non signal-based models

The `FormValueControl` and `FormCheckboxControl` interfaces still
require a `model()`-input, however, a custom control need not implement
either interface to be bound by the `Field` directive.

All of the following examples can be used to define a custom control:

```ts
// Preferred: model()
class MyFormControl implements FormValueControl<string> {
  readonly value: model.required<string>();
}

// Supported: input() + output()
class MyFormControl {
  readonly value: input.required<string>();
  readonly valueChange: output<string>();
}

// Supported: @Input() + @Output()
class MyFormControl {
  @Input({required: true}) value!: string;
  @Output() valueChange: new EventEmitter<string>();
}
```

The latter two may still choose to implement `FormUiControl` for other
properties, but again it is not required.

Fix #65478
2026-01-02 08:09:03 +01:00
Leon Senft
817e2b87a8 refactor(forms): always bind [field] to ControlValueAccessor if present
Change the order of precedence that `[field]` binds to from

  1. Custom control (`FormValueControl`, `FormCheckboxControl`)
  2. Interop control (`ControlValueAccessor`)
  3. Native control (`<input>`, `<select>`, `<textarea>`)

to

  1. Interop control (`ControlValueAccessor`)
  2. Custom control (`FormValueControl`, `FormCheckboxControl`)
  3. Native control (`<input>`, `<select>`, `<textarea>`)

This ensures that Reactive Forms controls authored to use
`ControlValueAccessor` work correctly with Signal Forms, even if they
happen to conform to the `FormValueControl` interface.
2026-01-02 08:09:03 +01:00
SkyZeroZx
4e7e38c591 refactor(core): Add ngDevMode guards and new sanitization error codes
Adds new runtime sanitization error codes. Adds `ngDevMode` guards around
error message strings to ensure detailed diagnostics are included only
in development mode. This allows production builds to tree-shake verbose error descriptions, reducing bundle size.
2026-01-02 08:08:21 +01:00
Andrew Scott
99ad18a4ee feat(core): Add stability debugging utility
This commit adds a utility method to debug why the application has not stabilized after
a set period of time (9 seconds, or `hydrationTimeout-1`).

fixes #52912
2025-12-17 15:43:05 -08:00
Alan Agius
f516370c8e fix(core): use mutable ResponseInit type for RESPONSE_INIT token
The `RESPONSE_INIT` token previously used `ResponseInit`. However, `@types/node` (and `undici`) definitions for `ResponseInit` mark properties as `readonly`, which differs from the standard DOM `ResponseInit`.

This commit introduces a `ResponseInit` type that explicitly removes `readonly` modifiers to ensure compatibility and allow for mutable options. This type is now used by the `RESPONSE_INIT` token and is exported from `@angular/core`.
2025-12-17 09:35:22 -08:00
SkyZeroZx
62ccd64e9f docs: add section about reactive contexts 2025-12-16 16:35:24 -08:00
Matthieu Riegler
6270bba056 ci: reformat files
This is after we've slightly changed a rule in #66056
2025-12-16 14:44:19 -08:00
Andrew Scott
06be8034bb fix(core): Microtask scheduling should be used after any application synchronization
Previously, Angular would switch from the macrotask to a microtask
scheduler _only_ when the scheduler was the trigger for the
synchronization. This microtask scheduling is to ensure patterns such as
`Promise.resolve().then(() => updateAppStateAgain())` _during_
synchronization are caught and synchronized again within the same event
loop (guaranteeing that they aren't split across multiple browser paints).

The microtask scheduler should be used after any tick, not just from
those than run within the scheduler to always account for the promises
within synchronization. This is encountered most frequently during
bootstrap, which triggers the tick directly.

In this change we exempt `TestBed.tick` and
`ComponentFixture.detectChanges` from this behavior. Doing so would affect
the timing of stability and tests are quite sensitive to this (e.g.
`fixture.whenStable`). It is somewhat unfortunate that we have "special" test-only
behavior. However, it is important to acknowledge that this only affects
the test-only APIs as well. Any code in the application under test that
triggers `ApplicationRef.tick` directly would still use the microtask
scheduling behavior.

fixes #65444
2025-12-16 13:34:48 -08:00
SkyZeroZx
bf2e50843d refactor(core): conditionally include debug names based on ngDevMode
Conditionally include debug-related metadata based on `ngDevMode` to avoid
unnecessary information in production builds.
2025-12-16 09:37:38 -08:00
Matthieu Riegler
b4f584cf42 fix(core): return StaticProvider for providePlatformInitializer
Returning `EnvironmentProviders` was never correct.
fixes #64277
2025-12-15 15:16:37 -08:00
SkyZeroZx
bb65520991 docs: Adds documentation for the NG0919 error
Adds a new documentation page for the NG0919 error, which indicates a circular dependency in Angular applications.

fixes  #65968
2025-12-15 09:52:16 -08:00
Kristiyan Kostadinov
7be4ddef1c fix(core): throw better errors for potential circular references
Currently circular references in user code manifest themselves with an error like `Cannot read properties of undefined (reading 'ɵcmp')`. This is a bit cryptic so these changes add an assertion mentioning circular references.

Relates to #65917.
2025-12-12 08:06:26 -08:00
SkyZeroZx
4f6014a756 fix(core): avoid false-positive deprecation when using InjectionToken with factory only
Prevents the deprecation warning that was incorrectly triggered when
defining an InjectionToken with only a `factory`, which correctly
defaults to the `root` scope.
2025-12-11 11:20:11 -08:00
SkyZeroZx
bff2dcb93c docs: update forwardRef usage with signals and add HostListener note 2025-12-10 12:23:29 -08:00
Matthieu Riegler
835a643161 refactor(core): Support Error like object for on resource errors.
Error like object will be treated as errors.

Related to #61861
2025-12-10 08:18:17 -08:00
arturovt
80dbd74ae8 refactor(core): wrap operationsCounter calls with ngDevMode checks
Wrap operationsCounter method calls (recordCreate, recordDestroy, reset)
with ngDevMode guards to ensure they are tree-shaken in production builds.

This aligns with the existing pattern where operationsCounter is only
initialized in development mode, and eliminates unnecessary method call
overhead in production.

The optional chaining (?.) is retained as TypeScript doesn't narrow types
based on ngDevMode checks, but the entire expression will be removed during
production builds.
2025-12-09 10:38:39 -08:00
Matthieu Riegler
8199945637 refactor(core): add dedicated deprecated signatures for providedIn: any / NgModule.
Those were deprecated by #47616 back in v15.

fixes #65923
2025-12-09 10:38:09 -08:00