Commit graph

3851 commits

Author SHA1 Message Date
Andrew Scott
ecae525970 Revert "refactor(core): remove ComponentFactoryResolver & ComponentFactory from the api surface"
This reverts commit 9d76ac8229.
g3 cleanup not complete
2026-04-06 09:24:11 -07:00
Kristiyan Kostadinov
9c55fcb3e6 feat(core): de-duplicate host directives
With host directives we can end up in a situation where the same directive applies multiple times to the same element, potentially with conflicting configurations. The runtime isn't set up for a directive to apply more than once so historically we were throwing an error when we detect duplicates.

This ended up limiting the usefulness of host directives to library authors, because it meant that host directives couldn't be reused as much as authors wanted. To address the issue, these changes introduce logic in the compiler and runtime that will de-duplicate host directives with the following logic:

1. If a directive matches once in the template and more than once as a host directive, the host directive matches will be discarded and only the template match will apply. The mental model is that a host directive match represents `Partial<YourDirective>` while a template match represents the full `YourDirective`.
2. If a directive matches multiple times as a host directive, we merge the input/output mappings from all the instances into a single one. If we detect a case where an input/output is exposed under multiple names during the merging process, both the compiler and the runtime will produce an error.

Fixes #57846.
2026-04-03 09:44:39 -07:00
Matthieu Riegler
9d76ac8229 refactor(core): remove ComponentFactoryResolver & ComponentFactory from the api surface
Those APIs date back to pre-ivy times and are long deprecated.

BREAKING CHANGE: `ComponentFactoryResolver` and `ComponentFactory` are no longer available. Pass the component class directly to APIs that previously required a factory, such as `ViewContainerRef.createComponent` or use the standalone `createComponentFunction`.
2026-04-02 16:00:57 -07:00
Jessica Janiuk
30f63fc1c2 refactor(core): address review comments on NG0750 error message
This commit addresses review comments from AndrewKushnir regarding conditional formatting of error messages and updating tests.
2026-04-02 14:55:42 -07:00
Jessica Janiuk
8218d2e34a refactor(core): Add more detail to NG0750 error message
This adds a bit more context to the NG0750 error message to provide details about which module failed to load when executing the dependencyResolverFn. This can help with debugging a failed lazy load in a defer block.
2026-04-02 14:55:42 -07:00
Alan Agius
e84e35cdd6 fix(core): prevent binding unsafe attributes on SVG animation elements (#67797)
SVG animation elements (`animate` and `set`) can be used to animate sensitive attributes like `href` or `xlink:href`. Binding to these animation attributes (like `to`, `from`, or `values`) with a sensitive target creates an XSS vector.

This change mitigates this risk by:
1. Classifying `to`, `from`, and `values` on `<animate>` and `<set>` elements as `ATTRIBUTE_NO_BINDING` in the DOM security schema to prevent standard dynamic bindings.
2. Adding runtime validations in `ɵɵvalidateAttribute` to verify that `attributeName` is not a sensitive attribute (such as `href` or `xlink:href`) when processed by a set of `SECURITY_SENSITIVE_ATTRIBUTE_NAMES`. If it is, a runtime error `UNSAFE_ATTRIBUTE_BINDING` is thrown.
3. Adding regression tests in `integration_spec.ts` to ensure unsafe bindings throw an error while safe ones pass correctly.

PR Close #67797
2026-04-01 11:43:58 +02:00
Alan Agius
028e1d3ce0 fix(core): treat object[data] as resource URL context (#67797)
Previously, the `data` attribute of the `<object>` tag was being sanitized as a regular URL instead of a `ResourceURL`, which is security-sensitive.
This commit updates the runtime sanitization logic to correctly identify `object[data]` as a `ResourceURL` context. Additionally, the sanitizer lookup logic has been refactored to use a more efficient lookup map (`RESOURCE_MAP`) instead of multiple `Set` lookups, providing better performance and maintainability.

Added tests to verify the correct sanitization of `object[data]` and its behavior with trusted values.

PR Close #67797
2026-04-01 11:43:58 +02:00
SkyZeroZx
43ef7171b3 docs: update change detection strategy references 2026-03-27 15:43:43 +01:00
Alex Rickabaugh
24e52d450d feat(forms): add debounce option to validateAsync and validateHttp
This adds support for a `debounce` option to the `validateAsync` and `validateHttp` functions.
This allows developers to debounce the triggering of async validators to improve performance.

A `DebounceTimer` type was also added to `@angular/core` to represent the wait condition parameters uniformly.
2026-03-25 14:17:52 -07:00
Matthieu Riegler
cf3b7fe489 refactor(core): remove todo
This TODO hinted that we also needed to remove a g3 patch.
2026-03-25 13:02:23 -07:00
Alex Rickabaugh
16adbbf423 fix(core): ensure custom controls resolve transitive host directives
Custom controls can be modeled using a set of host directives to alias
and expose value and valueChange (or checked/checkedChange) bindings,
as well as native attributes like disabled.

This commit updates initializeCustomControlStatus to correctly identify
host components using mapped inputs/outputs, even when those inputs are
exposed via transitive host directives. It also updates
customControlHasInput so that the custom control presence check correctly
evaluates the exposed inputs across all applied host directives, caching
the result to optimize performance on hot code paths.
2026-03-25 13:00:46 -07:00
Matthieu Riegler
eae8f7e30b feat(core): Set default Component changeDetection strategy to OnPush
The default change detection strategy is now OnPush.

BREAKING CHANGE: Component with undefined `changeDetection` property are now `OnPush` by default. Specify `changeDetection: ChangeDetectionStrategy.Eager` to keep the previous behavior.
2026-03-24 16:25:02 -07:00
Kristiyan Kostadinov
d9712e605e refactor(core): expand input flags type
Expands the type for the input flags in definitions since the current one prevents some of the generated code from compiling.
2026-03-24 15:18:28 -07:00
SkyZeroZx
26afb736b7 docs: Update provideZonelessChangeDetection tsdocs 2026-03-23 14:48:02 -07:00
Pushkar-Mahajan4
1128e78913 docs: fix typo in Input decorator 2026-03-23 11:19:46 -07:00
Matthieu Riegler
d2054c7c1a refactor: prepare for required changeDetection prop on G3.
We'll make this a G3 only change to prevent backsliding during the transition period.
2026-03-20 15:52:38 -07:00
splincode
c5da47f63f refactor: replace any with stricter types in common and core
- `JsonPipe.transform`: `any` → `unknown`
- `renderStringify`: `any` → `unknown`
- `NgLocalization.getPluralCategory`: `any` → `number`
2026-03-20 15:20:43 -07:00
Kristiyan Kostadinov
5e99ae9f00 fix(core): widen type for directive inputs/outputs
Currently the directive inputs and outputs are typed to match the members of the class. We can't guarantee that when generating code, because of cases like `model` where an output is generated implicitly.

These changes widen the type to be any string.
2026-03-20 15:18:29 -07:00
Kristiyan Kostadinov
22f8b0a500 fix(core): resolver function not matching expected type
Fixes that the `ɵɵresolveWindow` function wasn't match the type expected by `ɵɵlistener`. I've also added explicit type annotations to make cases like this easier to catch.
2026-03-20 15:18:29 -07:00
Alex Rickabaugh
50e599e73e fix(core): lazy-initialize debounced state to prevent computation cycle
When building a debounced resource, we previously eagerly started tracking the 'source' signal state by instantiating a regular signal. However, if this 'debounced' primitive is initialized in a computation reactive graph (like signal forms 'validateAsync'), reading the current UI source dependency eagerly can induce a cycle if we haven't finished calculating the graph node yet.

This fix uses a 'linkedSignal' block to define the eager 'source' instead. Because linkedSignals are lazy by default, this bypasses the initial eager evaluation, allowing the containing reactive graph to finish forming first without losing our timing logic inside the ambient effect().
2026-03-19 16:18:38 -07:00
Matthieu Riegler
e01573fbca docs: Add callout about the Component interface. 2026-03-19 16:14:18 -07:00
Jessica Janiuk
dfa149dc68 fix(core): fixes a regression with animate.leave and reordering
This fixes a regression bug that resulted in reordered elements not getting properly removed from the DOM. Reused nodes were not being cleared out in this situation.

fixes: #67728
2026-03-19 15:51:57 -07:00
Jessica Janiuk
890c97301f Revert "refactor(core): Ensure determineLongestAnimation is run synchronously after style applies"
This reverts commit 318ade062e.
2026-03-18 11:30:35 -06:00
JoostK
1eaf92077f refactor(core): declare explicit reactive node prototypes types
These type annotations allow TS to associate the object's properties
with their corresponding declaration in the interfaces, enabling
much better code navigation. For example, "Find all implementations"
for `ReactiveNode.producerRecomputeValue` now finds the implementation
in `COMPUTED_NODE` and `LINKED_SIGNAL_NODE`.
2026-03-17 14:00:11 -06:00
Matthieu Riegler
69fb1614ef refactor(core): remove checkNoChanges from the public API.
It's an internal API.

BREAKING CHANGE: `ChangeDetectorRef.checkNoChanges` was removed. In tests use `fixture.detectChanges()` instead.
2026-03-17 13:57:43 -06:00
Alex Rickabaugh
8587b08e88 refactor(core): JIT detection of ɵngControlCreate
Adds detection of the `ɵngControlCreate` special lifecycle hook to the JIT compiler.
2026-03-17 13:18:26 -06:00
Alex Rickabaugh
16783d5622 refactor(core): prepare control instruction for template & reactive interop
Add `nativeElement` and a few other affordances to the control instruction implementation.
2026-03-17 13:18:26 -06:00
hawkgs
264f3510a7 refactor(core): abstract control flow discovery utilities (#66167)
Create a universal mechanism for adding and managing control flow discovery utilities. Those utilities are intended to be consumed by third parties via the `ng` global interface.

PR Close #66167
2026-03-16 14:17:25 -07:00
Hryhorii Avcharov
41a392d85e feat(devtools): add support for @for control flow blocks in directive explorer (#66167)
- Handle @for data in tree strategies and view extraction
- Show @for details in the UI and property tab
- Persist @for state and update UI accordingly

PR Close #66167
2026-03-16 14:17:25 -07:00
Max Millien
dc0446552a fix(core): clean up dehydrated views during HMR component replacement
During HMR, `recreateLView()` destroys the old LView and removes its
DOM nodes, but never cleans up dehydrated view DOM nodes stored in
`LContainer[DEHYDRATED_VIEWS]`. These are SSR-rendered DOM nodes
preserved by Angular's hydration system. When the new view renders,
both the old dehydrated DOM and the new DOM coexist, causing visible
duplication (e.g. `<app-shell>` header/footer appearing twice).

Call `cleanupLView` from the hydration cleanup module after
`destroyLView` and before `removeViewFromDOM` to remove any remaining
dehydrated DOM nodes before the replacement view is rendered.

Fixes #66503
2026-03-16 10:04:06 -06:00
Kristiyan Kostadinov
814eaba265 refactor(core): update generated code signatures
Updates the signatures of generated code to match what the compiler actually generates.
2026-03-16 09:58:18 -06:00
Jessica Janiuk
318ade062e refactor(core): Ensure determineLongestAnimation is run synchronously after style applies
This adds a setTimeout, which guarantees that we call getAnimations one frame after a reflow is finished. This means getAnimations will return data, avoiding needing the expensive fallback of getComputedStyles. It also updates the cleanup to prevent a potential memory leak if the component is destroyed before the timeout runs.
2026-03-13 13:03:11 -06:00
Jessica Janiuk
df659b8d0c feat(core): re-introduce nested leave animations scoped to component boundaries
This commit re-introduces support for nested leave animations with a critical adjustment to prevent cross-component blocking. Wait for nested inner `animate.leave` transitions natively only when they exist within the same component's view or its embedded tracking structures (like `@if` and `@for`).

This resolves the issue where route navigations and parental destruction would excessively stall by traversing down into child component architectures to wait for their distinct leaf animations.

BREAKING CHANGE: Leave animations are no longer limited to the element being removed.

Fixes #67633
2026-03-13 13:01:55 -06:00
Kristiyan Kostadinov
412788fac9 fix(compiler): ensure generated code compiles
Initial pass to make sure some common cases produce code that compiles.
2026-03-13 11:13:03 -06:00
Jessica Janiuk
17d8a88ddc refactor(core): Update determineLongestAnimation to account for playback rate
This updates the determineLongestAnimation code to also calculate the playback rate in with the duration, which should also account for timing when testing with playback rates changed in devtools.
2026-03-12 17:36:50 -06:00
Alan Agius
bb628d8b50 refactor: ensure modules with 'declare global' are correctly handled by Rollup
Explicitly adding an `export {}` to modules containing `declare global` fixes an issue where Rollup would incorrectly claim that the `global` variable is not defined in the emitted `.d.ts` files.

Needed to land the latest `rules_angular`.
2026-03-12 14:58:00 -06:00
Kristiyan Kostadinov
de0eb4c656 fix(core): sanitize translated form attributes
Fixes that we weren't sanitizing the `form` and `formaction` attributes when they're used together with translations.
2026-03-12 11:01:26 -06:00
Jessica Janiuk
999c14eaab fix(core): reverts "feat(core): add support for nested animations"
This reverts commit ea2016a6dc.

This reverts the support for nested animations due to the global scope of how nested animations were gathered.
This caused issues where on route navigations, all child nodes with animations would be queued and run before the navigation would occur.
We'll be revisiting the nested animations with a more tightened scope of when those leave animations will occur.

fixes: #67552
2026-03-12 10:58:03 -06:00
JoostK
b401c18674 fix(core): include signal debug names in their toString() representation
The `toString()` implementations in the primitives package intended to include
the debug name, yet the debug name was evaluated during construction before it
could ever have been assigned. This commit fixes that.

The Angular wrappers override the `toString()` representation to evaluate signals
ad-hoc instead of showing their internal state, and this commit aligns their
behavior to include the debug name in `toString` as well.
2026-03-11 11:28:35 -07:00
SkyZeroZx
0837d25a70 refactor(common): Removes unused generic type parameters from KeyValueDiffers
Remove unused generic type parameters from KeyValueDiffers methods
2026-03-11 10:49:11 -07:00
Matthieu Riegler
4842f5a3b7 refactor(core): remove old resource params
G3 has been cleaned up we can drop those.
2026-03-11 10:44:12 -07:00
Ibrahim Hussien
903d51e855 docs: combine multiple documentation improvements into one PR 2026-03-11 09:29:45 -07:00
Matthieu Riegler
a675950e44 refactor(core): interface cleanup
Should be fine to land this time.
2026-03-10 12:44:32 -07:00
Kristiyan Kostadinov
8630319f74 fix(core): sanitize translated attribute bindings with interpolations
Fixes that we weren't sanitizing attribute bindings with interpolations if they're marked for translation, for example: `<a href="{{evilLink}}" i18n-href></a>`.

Also adds a bit more test coverage for our sanitization.
2026-03-10 11:13:49 -07:00
Jon Snow
196933863b docs(core): clarify provideZoneChangeDetection usage in v21+
Clarify that provideZoneChangeDetection() is used to opt applications into NgZone/ZoneJS-based change detection and to configure NgZone options such as eventCoalescing.

Fixes #67498
2026-03-10 10:21:07 -07:00
Kristiyan Kostadinov
f9ede9ec98 fix(core): ensure definitions compile
Includes the following changes to make sure the definitions for injectable compiler:
1. The types for the `factory` function now include the `parent` parameter.
2. `ɵɵFactoryDeclaration` is now defined as a function. We need this since the provider definition gets passed into the inejctable definition by reference.
3. `ɵɵdefineInjectable`, `ɵɵdefineNgModule` and `ɵɵdefinePipe` now return the typed definition, rather than `unknown`. This aligns with what we do for components and directives.
2026-03-10 09:58:18 -07:00
SkyZeroZx
6073493c5b docs: Adds @see links and update defer reference 2026-03-09 16:59:39 -07:00
Miles Malerba
b918beda32
feat(core): allow debouncing signals
Adds a utility `debounced` to create a debounced version of a signal,
represented as a `Resource`. The resource's value contained the
debounced value of the signal, while its status (`resolved`, `loading`,
or `error`) indicates if the value is settled, if there is a value
currently pending debounce, or if the source signal threw an error.
2026-03-09 13:21:52 -07:00
Matthieu Riegler
0afe3c00ae refactor(core): remove private export of getDebugNode
This is a public api
2026-03-09 11:21:19 -07:00
Andrew Scott
e97f5139ec refactor(core): update componentDeclaration to include isSignal
This is in DirectiveDeclaration and in the golden files with ComponentDeclaration
so I assume it was an accidental omission.
2026-03-09 11:17:38 -07:00