Commit graph

3271 commits

Author SHA1 Message Date
Matthieu Riegler
4812215a7b feat(core): Expose Injector.destroy on Injector created with Injector.create (#60054)
There is no implementation change, this only expose `destroy` in a case where the injector can be owned in userland.

PR Close #60054
2025-02-27 15:46:13 +00:00
Jessica Janiuk
0dbf693a4d fix(core): prevent invoking replay listeners on disconnected nodes (#60103)
This prevents replay from happening on nodes that have been removed from the DOM.

fixes: #59841

PR Close #60103
2025-02-27 15:45:14 +00:00
arturovt
8742f9cc74 refactor(core): tree-shake REF_EXTRACTOR_REGEXP (#60081)
The `REF_EXTRACTOR_REGEXP` is a `new` expression that has side effects and is not dropped in production, even if it is unused.

PR Close #60081
2025-02-26 11:17:48 -05:00
arturovt
11ab5db9bd refactor(core): inline depPath in throwCyclicDependencyError to be dropped (#60084)
Inlines the `depPath` within the `throwCyclicDependencyError`, because it's not being tree-shaken in production.

PR Close #60084
2025-02-26 11:10:36 -05:00
Andrew Scott
491b0a4ead fix(core): Remove duplicate reporting of errors in CDR.detectChanges (#60056)
This change removes the reporting of errors from the
`ChangeDetectorRef.detectChanges` API. The reporting results in the
error being "handled" in two ways, both by reporting to error handler
and rethrowing the error. This rethrown error generally ends up being
caught further up and again reported to the error handler. The error
handler is meant to be for uncaught errors, and since Angular is not at
the top of the stack of the call of `CDR.detectChanges`, it does not
know what is being done with the rethrown error.

Note that for zone-based applications, this will likely have no effect
other than removing duplicate reporting of the error. If the rethrown
error is not already being caught, it will reach the NgZone's error
trap and still be reported to the application `ErrorHandler`.

PR Close #60056
2025-02-25 12:20:22 -05:00
Pawel Kozlowski
af2e79eb41 refactor(core): remove performance mark feature for signals (#59991)
Remove the performance mark feature from the Angular signal impl
so more code can be shared between primitives and other frameworks.

PR Close #59991
2025-02-25 11:10:07 -05:00
Kristiyan Kostadinov
334d851010 refactor(core): add infrastructure for setting inputs on specific directives (#60075)
Sets up the infrastructure that will allow to write only to a specific directive and its host directives as a base for future functionality.

I've also renamed `setInputsForProperty` to be a bit more explicit that its sets all inputs.

PR Close #60075
2025-02-25 10:58:51 -05:00
Kristiyan Kostadinov
87a0fb9997 refactor(core): avoid memory allocations if there are no host directives (#60075)
Currently the host directive logic disassembles and re-assembles the array of directive matches, in case there are host directives which in most cases produces an identical array.

These changes add some logic so that we only need to allocate the additional memory if we actually need it.

PR Close #60075
2025-02-25 10:58:50 -05:00
Kristiyan Kostadinov
98bde739ac refactor(core): move component logic out of host directives resolution (#60075)
In order to mark a TNode as a component, we need to store the index of the component definition. Currently this happens in the logic that resolves host directives, because the component's host directives can move affect the index.

These changes move the logic out into the directive initialization logic since it doesn't have much to do with host directives.

PR Close #60075
2025-02-25 10:58:50 -05:00
Kristiyan Kostadinov
22d13bfba7 refactor(core): track match index of directives (#60075)
If we want to target an input write to a directive, we have to know the index at which its instance is stored. Technically we can already find this by looking through `TView.data`, but that'll require a linear lookup for each write which can get slow.

These changes introduce the new `TNode.directiveToIndex` map which allows us to quickly find the index of a directive based on its definition, as well as any host directives that its might've brought in.

PR Close #60075
2025-02-25 10:58:50 -05:00
Kristiyan Kostadinov
e601bdca8a fix(core): capture stack for HMR errors (#60067)
Currently we send the `message` of an error thrown during HMR. That's usually not enough so now we also capture the stack trace.

Relates to https://github.com/angular/angular-cli/issues/29695.

PR Close #60067
2025-02-24 11:56:15 -05:00
Kristiyan Kostadinov
628ab4033b refactor(core): do not store input/output public names (#60036)
Reworks the `TNode.inputs` and `TNode.outputs` to not store the public names of bindings. The only reason they were stored was for host directive re-aliasing which is handled through a different data structure now.

PR Close #60036
2025-02-21 14:07:34 -05:00
Kristiyan Kostadinov
9f44b41053 refactor(core): separate host directive inputs from selector-matched ones (#60036)
Currently `TNode.inputs`/`TNode.outputs` store all of the available bindings on that node, no matter if they came from a directive that the user applied directly or from a host directive. This has a couple of drawbacks:
1. We need to store more information that necessary. For example, the only reason we have strings in the arrays is to facilitate host directive aliasing.
2. It doesn't allow us to distinguish which host directives belong to which selector-matched directives.

These changes are a step towards resolving both issues by storing the host directive binding information in separate data structures.

PR Close #60036
2025-02-21 14:07:34 -05:00
Kristiyan Kostadinov
0cac2a22c0 refactor(core): rework how inputs/outputs are initialized (#60036)
Reworks the functions that create the `initialInputs`, `inputs` and `outputs` structures to initilize them within the function, instead of returning them to be initialized later. This will simplify future refactors where they'll produce more than one piece of information.

PR Close #60036
2025-02-21 14:07:34 -05:00
Pawel Kozlowski
5b7a936aff refactor(core): remove duplicated checks for ngNonBindable (#60048)
This refactoring consolidates logic around detecting ngNonBindable
mode - previously those checks were done in two separate places.
By doing the check in one place we can simplify the directive resolution
logic.

PR Close #60048
2025-02-21 11:08:49 -05:00
Jessica Janiuk
6e1ead6f93 refactor(core): clean up when blocks fail to fetch or hydrate (#59740)
There are cases where resources fail to fetch or the DOM has changed due to an if block. This should clean up the remaining promises and any registry references to those blocks in that case.

PR Close #59740
2025-02-21 11:08:03 -05:00
arturovt
35e25f690c refactor(core): drop platform check in ImagePerformanceWarning (#59809)
Replaces `PLATFORM_ID` checks with `ngServerMode`.

PR Close #59809
2025-02-20 12:32:22 -05:00
Andrew Scott
8657a0e4cc refactor(core): Add fake navigation to primitives for code sharing (#59857)
This moves the `FakeNavigation` implementation to the primitives folder
so its implementation can be shared with Wiz. This class was initially
copied directly from the Wiz implementation, with some small modifications.
There will still need to be some work done to align the implementations
and fix anything internally that needs adjusting.

PR Close #59857
2025-02-19 20:09:10 +00:00
arturovt
cf3a5073ec refactor(core): improve stringify (#59745)
In this commit, we improve branching in the `stringify` function, which is widely used by the framework, and add additional comments for clarification. Benchmark results of the old and new implementations (using `slice` makes it slightly faster) are as follows:
```
stringify (old version) x 117,945,419 ops/sec ±5.25% (55 runs sampled)
stringify (new version) x 136,692,820 ops/sec ±4.82% (56 runs sampled)
```

PR Close #59745
2025-02-19 15:21:36 +00:00
Kristiyan Kostadinov
f41437e6f5 refactor(core): simplify serialization of inputs and outputs (#59980)
Simplifies the functions that serialize inputs/outputs for the `ComponentFactory` type.

PR Close #59980
2025-02-18 19:28:00 +00:00
Kristiyan Kostadinov
9c6a0e5f01 refactor(core): add assertion to avoid writes to directive factories (#59980)
Attempting to write to directive inputs before the directive is created can lead to subtle issues that won't necessarily trigger errors. These changes add an assertion to catch such issues earlier.

PR Close #59980
2025-02-18 19:28:00 +00:00
Kristiyan Kostadinov
1b0fdc7eb1 refactor(core): avoid unnecessary lookup when writing inputs (#59980)
Currently we resolve the DOM node when writing inputs up-front, because it's necessary for the `ng-reflect-` attributes. Since the attributes are dev-mode-only, we can move the resolution into the function that writes them so we can avoid the resolution when it's not used.

PR Close #59980
2025-02-18 19:28:00 +00:00
Kristiyan Kostadinov
6a7fd11386 refactor(core): simplify InitialInputs data structure (#59980)
Reworks the `InitialInputs` data structure to only store a public name and initial value, resulting in less memory usage and making it easier to work with.

PR Close #59980
2025-02-18 19:28:00 +00:00
Kristiyan Kostadinov
5acdc6bd59 refactor(core): remove flags from TNode.inputs (#59980)
The input flags are already available on the definition so we don't need to store them on `TNode.inputs`.

PR Close #59980
2025-02-18 19:27:59 +00:00
Kristiyan Kostadinov
db530856a8 refactor(compiler): remove input transforms feature (#59980)
An earlier refactor made the `InputTransformsFeature` a no-op so these changes remove the code that was generating it.

PR Close #59980
2025-02-18 19:27:59 +00:00
Kristiyan Kostadinov
86086604f4 refactor(core): remove inputTransforms from definition (#59980)
Removes the `inputTransform` from the directive definition since this information is already available on the `inputs`.

PR Close #59980
2025-02-18 19:27:59 +00:00
Kristiyan Kostadinov
b8ad4c2117 refactor(core): simplify how inputs are stored in the directive definition (#59980)
Currently the values in `DirectiveDef.inputs` are either strings or arrays, depending if there are flags. This makes it a bit hard to work with, because each time it's read, the consumer needs to account for both cases.

These changes rework it so the values are always an arrays.

PR Close #59980
2025-02-18 19:27:59 +00:00
Pawel Kozlowski
c076b57986 refactor(core): move LContainer manipulation logic to its own file (#59856)
All the view in a container logic is in the
packages/core/src/render3/view/container.ts file
plus some other associated refactorings.

PR Close #59856
2025-02-18 15:41:42 +00:00
Alex Rickabaugh
3e39da593a feat(common): introduce experimental httpResource (#59876)
`httpResource` is a new frontend to the `HttpClient` infrastructure. It
declares a dependency on an HTTP endpoint. The request to be made can be
reactive, updating in response to signals for the URL, method, or otherwise.
The response is returned as an instance of `HttpResource`, a
`WritableResource` with some additional signals which represent parts of the
HTTP response metadata (status, headers, etc).

PR Close #59876
2025-02-14 18:40:37 +00:00
arturovt
20f5dc5103 refactor(core): simplify concatStringsWithSpace (#59820)
The new version of the function is smaller, eliminating extra bytes. The refactor improves both code size and readability while optimizing the implementation. Benchmark results for the old and new implementations are as follows:

```
concatStringsWithSpace_old x 149,225,311 ops/sec ±8.54% (50 runs sampled)
concatStringsWithSpace_new x 160,206,834 ops/sec ±5.72% (54 runs sampled)
```

Thus, the new implementation is both smaller and faster.

PR Close #59820
2025-02-13 15:10:42 +00:00
Miles Malerba
6789c7ef94 fix(core): Defer afterRender until after first CD (#59455) (#59551)
This reverts commit ac2dbe3eb1.

PR Close #59551
2025-02-12 12:20:04 -08:00
Miles Malerba
c87e581dd9 fix(core): Don't run effects in check no changes pass (#59455) (#59551)
This reverts commit 21f1ba22a6.

PR Close #59551
2025-02-12 12:20:04 -08:00
Kristiyan Kostadinov
b0266bda4a fix(core): invalidate HMR component if replacement throws an error (#59854)
Integrates https://github.com/angular/angular-cli/pull/29510 which allows us to invalidate the data in the dev server for a component if a replacement threw an error.

PR Close #59854
2025-02-12 09:05:30 -08:00
Kristiyan Kostadinov
e47c1e5abe refactor(compiler): pass more information to HMR replacement function (#59854)
Adjusts the code we generate for HMR so that it passes in the HMR ID and `import.meta` to the `replaceMetadata` call. This is necessary so we can do better logging of errors.

PR Close #59854
2025-02-12 09:05:30 -08:00
Alex Rickabaugh
b592b1b051 fix(core): fix race condition in resource() (#59851)
The refactoring of `resource()` to use `linkedSignal()` introduced the
potential for a race condition where resources would get stuck and not update
in response to a request change. This occurred under a specific condition:

1. The request changes while the resource is still in loading state
2. The resource resolves the previous load before its `effect()` reacts to the
   request change.

In practice, the window for this race is small, because the request change in
(1) will schedule the effect in (2) immediately. However, it's easier to
trigger this sequencing in tests, especially when one resource depends on the
output of another.

To fix the race condition, the resource impl is refactored to track the request
in its state, and ignore resolved values or streams for stale requests. This
refactoring actually makes the resource code simpler and easier to follow as
well.

Fixes #59842

PR Close #59851
2025-02-05 15:01:02 -08:00
Miles Malerba
a299e02e91 fix(core): preserve tracing snapshot until tick finishes (#59796)
This change waits until the end of `tick` to clear the tracing snapshot.
This ensures that if we notify the scheduler during `tick` the correct
tracing snapshot is used.

PR Close #59796
2025-02-05 09:00:49 -08:00
Pawel Kozlowski
41b1a7c582 refactor(core): minor code cleanups (#59843)
Some minor code cleanups after code changes in
previous commits.

PR Close #59843
2025-02-05 08:56:28 -08:00
Pawel Kozlowski
d8fca6d3df refactor(core): reuse element end first creation pass (#59843)
Reuse element end first creation pass in ComponentRef impl.

PR Close #59843
2025-02-05 08:56:28 -08:00
Pawel Kozlowski
5e0dcf1f53 refactor(core): reuse element first create pass in ComponentRef (#59843)
Reuse element first create pass in ComponentRef.

PR Close #59843
2025-02-05 08:56:28 -08:00
Pawel Kozlowski
e3dcf523ea refactor(core): move directive matching logic to a separate file (#59843)
Move directive matching logic to a separate file.

PR Close #59843
2025-02-05 08:56:27 -08:00
Pawel Kozlowski
2d53bacec3 refactor(core): reuse existing logic in ComponentRef impl (#59806)
This change removes some code and logic duplication by
re-using the existing functionality. It also pulls some
code into separate methods for clarity.

PR Close #59806
2025-02-03 13:57:10 -08:00
Andrew Scott
ad88304233 refactor(core): move callAndReportToErrorHandler to bootstrap file (#59793)
This function is only used in the bootstrap file and does not need to be in application_ref

PR Close #59793
2025-02-03 13:54:40 -08:00
arturovt
cf9054248d fix(core): check whether application is destroyed before printing hydration stats (#59716)
In this commit, we check whether the application is destroyed before printing hydration stats. The application may be destroyed before it becomes stable, so when the `whenStableWithTimeout` resolves, the injector might already be in a destroyed state. As a result, calling `injector.get` would throw an error indicating that the injector has already been destroyed.

PR Close #59716
2025-01-29 08:43:34 -08:00
Kristiyan Kostadinov
96e602ebe9 fix(core): cancel in-progress request when same value is assigned (#59280)
Fixes that `resource` wasn't cancelling its in-progress request if the same value as the current one is assigned.

Fixes #59272.

PR Close #59280
2025-01-29 08:40:11 -08:00
Luan Gong
b16d8a1c55 docs(core): Fix typo in documentation of linkedSignal (#59752)
PR Close #59752
2025-01-28 19:14:21 +01:00
Pawel Kozlowski
c202682957 refactor(core): reuse host directive resolution logic (#59685)
Reuse host directive resolution logic in ComponentRef

PR Close #59685
2025-01-28 11:31:29 +01:00
Alex Rickabaugh
6c92d65349 fix(core): add hasValue narrowing to ResourceRef (#59708)
`hasValue` attempts to narrow the type of a resource to exclude `undefined`.
Because of the way signal types merge in TS, this only works if the type
of the resource is the same general type as `hasValue` asserts.

For example, if `res` is `WritableResource<string|undefined>` then
`.hasValue()` correctly asserts that `res` is `WritableResource<string>` and
`.value()` will be narrowed. If `res` is `ResourceRef<string|undefined>`
then that narrowing does _not_ work correctly, since `.hasValue()` will
assert `res` is `WritableResource<string>` and TS will combine that for a
final type of `ResourceRef<string|undefined> & WritableResource<string>`.
The final type of `.value()` then will not narrow.

This commit fixes the above problem by adding a `.hasValue()` override to
`ResourceRef` which asserts the resource is of type `ResourceRef`.

Fixes #59707

PR Close #59708
2025-01-28 09:40:29 +01:00
Alex Rickabaugh
127fc0dc84 fix(core): fix resource()'s previous.state (#59708)
When a resource first starts up, even if it transitions immediately to
`Loading` it should report a `previous.state` of `Idle`. It was reporting
`Loading` as the previous state in such a case because of an oversight in
the migration to `linkedSignal` which this commit addresses.

PR Close #59708
2025-01-28 09:40:29 +01:00
Pawel Kozlowski
df143b486b refactor(core): remove unused LifecycleHooksFeature (#59678)
LifecycleHooksFeature seems to be unused and can be deleted.

PR Close #59678
2025-01-27 13:15:21 +01:00
Pawel Kozlowski
cfa9fc2098 refactor(core): simplify ComponentRef creation (#59678)
Move more logic to a constructor of a ComponentRef.

PR Close #59678
2025-01-27 13:15:21 +01:00