Commit graph

5252 commits

Author SHA1 Message Date
Kristiyan Kostadinov
ebfbaeba54 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:17 -05:00
Kristiyan Kostadinov
35d20cb4b4 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:35 -05:00
Kristiyan Kostadinov
352021e1d2 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:35 -05:00
Kristiyan Kostadinov
285abbb38f 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:35 -05:00
Pawel Kozlowski
ea8662ab3e 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:50 -05:00
Jessica Janiuk
1d28a42815 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:04 -05:00
arturovt
21740846b5 refactor(core): drop platform check in ImagePerformanceWarning (#59809)
Replaces `PLATFORM_ID` checks with `ngServerMode`.

PR Close #59809
2025-02-20 12:32:23 -05:00
Andrew Scott
f88ed8e470 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
86610f7bad build: update bundle goldens (#59980)
Updates the bundle goldens to account for the latest changes.

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
Enea Jahollari
1cd3a7db83 feat(migrations): add migration to convert templates to use self-closing tags (#57342)
This schematic helps developers to convert their templates to use self-closing tags mostly as a aesthetic change.

PR Close #57342
2025-02-18 17:33: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
iteriani
8b757bf35c refactor(core): Check in some interfaces for the DI package (#59921)
This will be the starting point of the DI package. We will first check in some interfaces and then make sure the existing DI package implements that interface. Afterwards, we'll slowly start moving injector implementation.

PR Close #59921
2025-02-13 20:19:29 +00:00
Matt Turco
2588985f43 feat(core): pass signal node to throwInvalidWriteToSignalErrorFn (#59600)
Updates the signature of the `throwInvalidWriteToSignalError` to take the signal node in question and pass it along to the throwInvalidWriteToSignalErrorFn handler function. This allows the handler to e.g. include the signal name in error messaging.

PR Close #59600
2025-02-13 17:56:14 +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
aa285c548c fix(migrations): account for let declarations in control flow migration (#59861)
Fixes that the control flow migration wasn't accounting for `@let` when determining which symbols are used.

PR Close #59861
2025-02-12 09:45:14 -08:00
Kristiyan Kostadinov
1119f85ca9 fix(migrations): count used dependencies inside existing control flow (#59861)
Fixes that the control flow migration wasn't checking the content of pre-existing control flow nodes for dependencies.

Fixes #59846.

PR Close #59861
2025-02-12 09:45:14 -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
Jeremias Peier
fa0c3e3210 feat(forms): support type set in form validators (#45793)
Previously, using `Validators.required`, `Validators.minLength` and `Validators.maxLength` validators don't work with sets because a set has the `size` property instead of the `length` property. This change enables the validators to be working with sets.

PR Close #45793
2025-02-05 08:59:55 -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
Kristiyan Kostadinov
146ab9a76e feat(core): support TypeScript 5.8 (#59830)
Updates the repo to support TypeScript 5.8 which is currently in beta.

PR Close #59830
2025-02-03 14:00:41 -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
Kristiyan Kostadinov
ea2ea5e65b test(core): update tests that were relying on implicit animations module (#59762)
We had some tests that were relying on the fact that the server module was importing animations implicitly.

PR Close #59762
2025-01-29 10:52:18 -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
Pawel Kozlowski
9af14b25d1 refactor(core): simplify attributes extraction logic for ComponentRef (#59678)
Make extractAttrsAndClassesFromSelector to return TAttributes directly to
simplify the overall logic and remove unecessary code.

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