3835 Commits

Author SHA1 Message Date
AleksanderBodurri 019a0f4c22 fix(core): load global utils before creating platform injector in the standalone case (#52365)
This is needed so that the providers configured on platform creation are picked up by the injector profiler.

PR Close #52365
2023-10-25 10:51:21 -07:00
AleksanderBodurri 78533324dc fix(core): get root and platform injector providers in special cases (#52365)
Previously, because the platform injector does not have a provider container, this API would fail. Now, we account for this case specifically by returning the found providers immediately, without trying to calculate their importpaths.

Also previously, in the case where a boostrapped standalone component did not import any feature modules, the environment injector connected to that bootstrapped component would be the root injector configured by `bootstrapApplication`. This injector is configured through a `providers` array instead of an `imports` array, and also does not have a provider container. Similarly to the platform case, we account this for this by returning the found providers immediately if there is no provider container for our standalone component.

PR Close #52365
2023-10-25 10:51:21 -07:00
AleksanderBodurri 54ea3b65c3 fix(core): emit provider configured event when a service is configured with providedIn (#52365)
Previously this case was missed by the default framework injector profiler. Now in ngDevMode this event emits correctly when a service is configured with `providedIn`. This includes the case where injection tokens are configured with a `providedIn`.

This commit also includes unit tests for this new case in the injector profiler.

PR Close #52365
2023-10-25 10:51:21 -07:00
Naaajii 3afee8716d docs(docs-infra): fix codeblock snippet for APP_INITIALIZER (#52354)
fixes broken code snippet for standalone application using APP_INITIALIZER

PR Close #52354
2023-10-25 09:34:47 -07:00
Matthieu Riegler 56c93d02b5 docs(core): fix the language code (#52352)
PR Close #52352
2023-10-25 09:32:18 -07:00
Andrew Scott 1693846a9b test(core): fix test observing broken OnPush checkNoChanges (#52337)
The test is actually observing that OnPush results in a view not being checked
when checkNoChanges runs.

PR Close #52337
2023-10-24 09:21:52 -07:00
Paul Gschwendtner d75eaa7375 refactor(core): remove unused helper for setting LView for reactive consumer (#52192)
This code path is never hit because the assignment of the lview happens
in `commitLViewConsumerIfHasProducers`.

PR Close #52192
2023-10-13 14:08:34 +02:00
Thabo 2bfd28c396 docs: correct wording for Directive's decorator host property key description (#51977)
PR Close #51977
2023-10-10 11:22:19 -07:00
Phalgun Vaddepalli d3c9e436a9 docs(core): add an example of configuring APP_INITIALIZER token in context of standalone components (#52084)
docs(core): fix formatting

PR Close #52084
2023-10-10 11:18:37 -07:00
Andrew Scott 334fe60c17 refactor(core): Update view flags so only one number needs adjustment (#51839)
When adding a new view flag, you currently need to adjust the last number of the last
3 flags. All of these share the same number so the shifting ones can just use
the base-10 IndexWithinInitPhaseShift.

PR Close #51839
2023-10-04 07:29:16 -07:00
Joey Perrott 781bb91f43 build: lock file maintenance (#51838)
Update the lock file.

PR Close #51838
2023-10-02 08:15:28 -07:00
Pawel Kozlowski 39a3e34e03 fix(core): allow toSignal calls in reactive context (#51831) (#51892)
This PR moves the Observable subscription of toSignal outside of the
reactive context. As the result the toSignal calls are allowed in the
computed, effect and all other reactive consumers.

This is based on the reasoning that we already allow signals creation
in a reactive context. Plus a similar change was done to the async pipe
in the https://github.com/angular/angular/pull/50522

Fixes #51027

PR Close #51892
2023-09-27 10:30:15 -07:00
Andrew Kushnir 68648ee684 refactor(core): avoid an empty array allocation during hydration (#51917)
This commit updates hydration runtime code to avoid creating an empty array when we can avoid it. Instead, we just check whether the field is `null` directly (without using nullish coalescing).

PR Close #51917
2023-09-27 09:22:50 -07:00
Paul Gschwendtner 03127fc870 refactor(core): ensure reactive node constants are considered pure (#51809) (#51813)
Currently when ESBuild bundles an application importing from
`@angular/core`, the signals library will be discovered during
export analysis. ESBuild will come across the constants for the reactive
signal graph- and end up considering some of these as side-effects given
the pattern of using a spread assignment for extending from e.g.
`REACTIVE_NODE` (a similar issue may occur if we e.g. extend from the
computed reactive node).

See more details on the issue: https://github.com/evanw/esbuild/issues/3392

Even though, ESBuild preserves these constants now, and all of its
dependencies— Terser will consider these as side-effect free and
eliminate these constants. This may require multiple passes though, and
might not be sufficient, depending on the chain of reactive node
extensions. E.g. in the signals branch we noticed some constants
unnecessarily being preserved.

PR Close #51809

PR Close #51813
2023-09-18 15:37:13 +02:00
Paul Gschwendtner 3b46066ff0 refactor: ensure top-level symbols are marked as side-effect free (#51776)
Terser does not treat `Symbol` as side-effect free- so if we end up with
a symbol export being loaded, it will result in the symbol being
retained.

We noticed this in the signals prototyping where symbols exported
from `computed` ended up appearing in symbol bundling tests.

PR Close #51776
2023-09-15 15:53:51 +02:00
JoostK 7b40d74fb4 refactor(core): let reactive node prototypes conform to their type (#51722) (#51772)
This commit adds explicit type annotations to the reactive node prototype objects,
such that the prototypes are type-checked against the interface they are supposed
to (partially) implement. This also allows IDEs to better track usages of reactive
node properties, improving code navigation.

PR Close #51722

PR Close #51772
2023-09-14 12:51:30 +02:00
JoostK 82712f80df fix(core): ensure a consumer drops all its stale producers (#51722) (#51772)
When a producer is no longer used, the consumer has to update its internal data structure
that keeps track of all producers. There used to be an issue where only half of the stale
producers would actually be removed from this data structure, as the intended upper bound
of the number of producers to remove would decrease with each removed producer, therefore
not reaching all producers that should be removed from the data structure.

This commit fixes the issue by truncating the arrays directly, without going through
individual `pop` operations. An assertion that would catch the inconsistent state in
the internal data structures of the signal graph has been introduced.

PR Close #51722

PR Close #51772
2023-09-14 12:51:30 +02:00
Gerald Monaco c700418ab8 refactor(core): delegate afterRender errors to an ErrorHandler (#51711)
Improves the error handling story for after*Render by delegating errors to an ErrorHandler, so that one failure does not break every callback.

PR Close #51711
2023-09-08 14:21:06 -07:00
Gerald Monaco 867b380f64 refactor(core): make AfterRenderEventManager tree-shakable (#51711)
In preparation for adding support for phases to after*Render, which will increase the implementation size, this commit splits out the optional logic so that it can be tree-shaken and dynamically loaded.

PR Close #51711
2023-09-08 14:21:06 -07:00
AleksanderBodurri 1122afd656 refactor(core): implement __ignore_ng_zone__ flag (#51339)
This flag allows message event listeners to prevent callbacks from executing within the NgZone if they contain a special `__ignore_ng_zone__` flag.

This functionality is built with Angular DevTools in mind, where it prevents an infinite change detection loop in inspecting applications that have message event listeners:

CD -> Inspected app emits componentTreeDirty event to DevTools -> DevTools emits event to get new component Tree from Inspected app -> Inspected app message event listener fires -> CD

PR Close #51339
2023-09-05 18:16:33 +00:00
hiepxanh 8ce22ebae3 docs: fix missing information in createComponent (#51493)
PR Close #51493
2023-09-01 16:15:13 +00:00
hiepxanh 137195cd26 docs: add viewContainerRef example (#51573)
PR Close #51573
2023-09-01 16:14:40 +00:00
Alex Rickabaugh f56b6555bd refactor(core): switch signals to a refcounting algorithm (#51226)
This commit switches the signals library from a bidirectional symmetric
dependency graph using weak references, to a bidirectional _asymmetric_
graph which uses strong references. This is made possible with a reference
counting algorithm which only tracks producer -> consumer references for
effect-like "live" consumers, preventing memory leaks.

The new algorithm should be simpler and faster than the previous
implementation as weak references are fairly slow to create and traverse.
A tradeoff is that non-live consumers must now poll their producers when
read, as they cannot rely on dirty notifications.

As part of this refactoring, the `ReactiveNode` class is replaced with an
interface instead, and methods are moved to standalone functions. This is
paired with instantiating individual signals/computeds via `Object.create`
against a prototype node which contains static or initial values. This
technique, in conjunction with the rest, greatly improves the performance
of node creation.

PR Close #51226
2023-09-01 14:18:41 +00:00
Pawel Kozlowski 7bb4f9126b refactor(core): remove duplicated access to TView (#51610)
Tiny refactoring to remove repeated field access to LView.

PR Close #51610
2023-09-01 14:18:06 +00:00
Matthieu Riegler b1a3925794 refactor(core): Use intersections on branded types. (#49702)
An Intersection on a branded type allows us to remove some unecessary type assertions.

PR Close #49702
2023-08-31 20:22:12 +00:00
Luis Castro dc4f77c851 docs(core): clarify InjectionToken usage (#51386)
- Emphasized the importance of using the same InjectionToken instance for both provider and injection call.
- Added examples to illustrate correct usages to prevent NullInjectorError.

PR Close #51386
2023-08-30 15:53:24 +00:00
Joey Perrott e6b301caa2 fix(core): remove unnecessary escaping in regex expressions (#51554)
Correct various Useless regular-expression character escape issues.

PR Close #51554
2023-08-29 21:52:34 +00:00
Joey Perrott dcd1add06f fix(core): correct incomplete escaping (#51557)
Correct incomplete escaping and replace all instances of comment delimiters

PR Close #51557
2023-08-29 19:48:26 +00:00
Gerald Monaco 0c7c852ee7 fix(core): run afterRender callbacks outside of the Angular zone (#51551)
afterRender should run outside of the Angular zone so that it does not trigger further CD cycles

PR Close #51551
2023-08-29 17:54:20 +00:00
Andrew Kushnir 20d62603c2 fix(core): handle hydration of view containers that use component hosts as anchors (#51456)
This commit fixes an issue where serialization of a view container fails in case it uses a component host as an anchor. This fix is similar to the fix from #51247, but for cases when we insert a component (that acts as a host for a view container) deeper in a hierarchy.

Resolves #51318.

PR Close #51456
2023-08-29 16:37:50 +00:00
Andrew Scott 157415831c refactor(router): Have router subscribe to transition events to update state (#48427)
Rather than the navigation transitions managing Router state, this
commit updates the Router to manage its own state based on ongoing
transition events. In the future, this can be abstracted even further to
have a totally separate class that manages the Router state. This would
allow the potential for swapping state manager implementations rather
than having to implement all types of state management in a single place.

One finding during tests was that unexpected errors thrown by the state management code moved
to the Router here will no longer be caught by the transition pipe's `catchError`.
This only includes calls to the following public Api methods:

* `go`, `replaceState`, `historyGo`, `isCurrentPathEqualTo` on `Location`
* `UrlSerializer.serialize`
* `UrlHandlingStrategy.merge`.

None of these methods should throw if the router is expected to function.
These might throw when tests include incomplete mocks, which is not
supported, or in cases where the actual browser methods like
`replaceState` would throw. This will already result in unexpected/unsupported
behavior. The failure case here is now arguably better - the navigation
itself still completes but the state update (either updating Router
internal state or updating the browser URL) fails separately and is
unhandled.

PR Close #48427
2023-08-22 08:04:01 -07:00
Matthieu Riegler 36f434e49d fix(core): guard the jasmine hooks (#51394)
This commit fixes a regression introduced in #50063

Fixes #51382

PR Close #51394
2023-08-21 08:14:54 -07:00
Matthieu Riegler bd4d2bbc1e docs: fix see also links. (#51379)
These were all the @see with no links.

PR Close #51379
2023-08-17 10:18:34 -07:00
Gerald Monaco 7a090eee96 refactor(core): Ensure hydration cleanup runs in the Angular zone (#51321)
Hydration cleanup needs to run in the Angular zone so that change detection will run.

PR Close #51321
2023-08-15 16:02:06 -07:00
Matthieu Riegler 252b111d1e docs: Improve host binding docs (#51326)
This commit adds the mention of the support of styles/classes/attributes in host bindings.

fixes # 44296

PR Close #51326
2023-08-15 09:54:14 -07:00
Matthieu Riegler 094d733654 docs: Add Missing SSR integrity marker error doc page (#51340)
This commit adds an error doc page for error 507 : Missing SSR content integrity marker.

PR Close #51340
2023-08-14 14:39:25 -07:00
Jeff Schiller 951ef93aa6 docs(core): Fix minor typo in comment of injector_compatibility.ts (#51324)
PR Close #51324
2023-08-14 08:56:29 -07:00
Andrew Kushnir 9f490da7e2 fix(core): handle hydration of view containers for root components (#51247)
For cases when a root component also acts as an anchor node for a ViewContainerRef (for example, when ViewContainerRef is injected in a root component), there is a need to serialize information about the component itself, as well as an LContainer that represents this ViewContainerRef. Effectively, we need to serialize 2 pieces of info: (1) hydration info for the root component itself and (2) hydration info for the ViewContainerRef instance (an LContainer). Each piece of information is included into the hydration data (in the TransferState object) separately, thus we end up with 2 ids. Since we only have 1 root element, we encode both bits of info into a single string: ids are separated by the `|` char (e.g. `10|25`, where `10` is the ngh for a component view and 25 is the `ngh` for a root view which holds LContainer).

Previously, we were only including component-related information, thus all the views in the view container remained dehydrated and duplicated (client-rendered from scratch) on the client.

Resolves #51157.

PR Close #51247
2023-08-07 09:24:26 -07:00
Matthieu Riegler b95b5b55d8 refactor(core): throw an error when hydration marker is missing from DOM (#51170) (#51276)
non-destructive hydration expects the DOM tree to have the same structure in both places.
With this commit, the app will throw an error if comments are stripped out by the http server (eg by some CDNs).

PR Close #51276
2023-08-07 09:22:51 -07:00
Matthieu Riegler 26781fd0fe refactor(core): remove unnecessary import for custom expect. (#51216)
Also adding some missing assertion after `expect()`

PR Close #51216
2023-08-07 09:22:20 -07:00
Matthieu Riegler c7c0723c7f refactor(core): deprecate PACKAGE_ROOT_URL token (#51222)
Usage was removed in #43884

PR Close #51222
2023-08-07 09:21:46 -07:00
Pawel Kozlowski e01549b26b refactor(core): introduce LView and LContainer utility functions (#51191)
This refactoring adds utility functions to add / remove LView from LContainer.
Those utils are preparation for the control flow and defer work.
Existing code was refactored to use the new utility functions and avoid
any code duplication.

PR Close #51191
2023-08-04 16:00:46 -04:00
Gerald Monaco e53d4ecf4c feat(core): add afterRender and afterNextRender (#50607)
Add and expose the after*Render functions as developer preview

PR Close #50607
2023-08-01 13:02:27 -07:00
Matthieu Riegler 8913d3e407 docs: fix warning about an unknown decorator (#51237)
dgeni was complaning about an unknown decorator (`@Input`)

PR Close #51237
2023-08-01 13:00:53 -07:00
Matthieu Riegler 4602545fe6 refactor(core): remove useless hack (#51224)
This hack is remnant of the Ivy migration.

PR Close #51224
2023-08-01 12:12:52 -07:00
Matthieu Riegler d81d125814 refactor(core): Remove dead unit test code (#51223)
This code is duplicated but unused.

PR Close #51223
2023-08-01 12:10:57 -07:00
Matthieu Riegler 9d59764ffc refactor(core): createInjector is a private function (#51221)
`createInjector` is not public.

PR Close #51221
2023-08-01 12:10:20 -07:00
Matthieu Riegler 737ed23e22 refactor(core): removing reflect-metadata from symbol tests. (#51217)
We were not reyling on it anymore.

PR Close #51217
2023-08-01 12:09:25 -07:00
Matthieu Riegler a871e23857 docs: remove duplicate words. (#51215)
Using the `\b(\w+)\s+\1\b` we can find duplicate word. Let's remove them.

PR Close #51215
2023-08-01 12:08:33 -07:00
Andrew Kushnir efb486e8bc refactor(compiler): handle defer blocks in TemplateDefinitionBuilder (#51162)
Updates the TemplateDefinitionBuilder class to generate the `defer` instruction for `{#defer}` blocks. Also generates dependency function that would be invoked at runtime (with dynamic imports inside).

PR Close #51162
2023-08-01 11:50:05 -07:00