Commit graph

9858 commits

Author SHA1 Message Date
Andrew Kushnir
59837f4749 refactor(platform-server): import xhr2 dynamically in the ServerXhr class (#50095)
This commit updates the `@angular/common/http` and `@angular/platform-server` packages to allow dynamic import of the `xhr2` dependency. The `xhr2` dependency has side-effects that rely on a global scope and as a result in some environments those side-effectful calls fail. With the changes from this PR, the import is delayed until it's actually needed, which gives a chance for the underlying platform to setup global scope (via shims) as needed.

Co-authored-by: alan-agius4 <17563226+alan-agius4@users.noreply.github.com>

PR Close #50095
2023-05-08 14:32:43 -07:00
Matthieu Riegler
73fcf9f20b refactor(core): remove webworker related checks on assertDomNode (#50061)
Since the drop of the webworker platform the node can't be a `WebWorkerRenderNode`.

PR Close #50061
2023-05-08 14:30:39 -07:00
Dylan Hunn
f780d6f202 refactor(compiler): extract save/restore view logic to separate phase (#50008)
Saving and restoring the view is significant enough that it makes sense to handle it independently. This makes for easier reasoning about how view save/restore works.
Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #50008
2023-05-08 14:30:13 -07:00
Dylan Hunn
6de4f26360 refactor(compiler): support KeyedRead expressions (#50008)
The compiler can now accept key read expressions (e.g. `foo[bar]`), where both the receiver and index are sub-expressions.

PR Close #50008
2023-05-08 14:30:13 -07:00
Dylan Hunn
2d6c49e5d2 refactor(compiler): generate property instructions for ng-template inputs (#50008)
When ingesting an `ng-template`, inputs might be on the `inputs` or the `templateAttrs` field. More investigation is required to pinpoint the specifics of `templateAttrs`.

For now, we can process them both and generate the appropriate update-mode property instructions.

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #50008
2023-05-08 14:30:13 -07:00
Dylan Hunn
9fa4677d2f refactor(compiler): handle chains in event listeners (#50008)
It's possible to have chains of statements, exclusively in event listeners. A listener with a chain looks like the following:

```
(click)="onClick($event); 1 == 1"
```

We handle this by generating multiple statements, one for each expression in the chain, and only making the final statement the return statement. We place this logic in code specific to listeners, since they are the only place this construct can appear.

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #50008
2023-05-08 14:30:13 -07:00
Dylan Hunn
e475b86961 refactor(compiler): handle binary operators (#50008)
We should be able to ingest binary operators. This involves parsing the left and right ASTs, and converting the operator string to a logical `BinaryOperator`.

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #50008
2023-05-08 14:30:13 -07:00
Dylan Hunn
8a751990a1 refactor(compiler): generate ng-container instructions (#50008)
ElementContainer instructions refer to `ng-container` element tags, which don't produce corresponding DOM nodes. Much like element instructions, container instructions can also have their start and end tags combined.

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>
Co-authored-by: Andrew Scott <atscott@users.noreply.github.com>

PR Close #50008
2023-05-08 14:30:13 -07:00
Alex Rickabaugh
9d4842cadb Revert "docs(docs-infra): Remove unused annotation template (#50114)" (#50206)
This reverts commit a1ca162fd6.

This commit causes failures in g3, because `@Annotation` is load-bearing for
tsickle's decorator downleveling transformation.

PR Close #50206
2023-05-08 09:45:35 -07:00
Matthieu Riegler
80fe08be96 refactor(platform-browser): Throw tree-shakable errors. (#49341)
In a effort to have more tree-shakable errors, this commit transforms every `Error` into a tree-shakable `RuntimeError`

PR Close #49341
2023-05-04 12:21:20 +02:00
Matthieu Riegler
39d2ea0a4d docs: remove mentions of the WebWorker platform (#50059)
The webworker platform was dropped in v11.

PR Close #50059
2023-05-04 09:06:55 +02:00
Matthieu Riegler
ec968a99d5 refactor(animations): remove circular deps (#50049)
`AnimationDriver` was not used in shared.ts.

PR Close #50049
2023-05-04 08:58:25 +02:00
Kristiyan Kostadinov
cb8cdadd3b refactor(compiler): reflect arrow function definition (#50084)
Adds some logic to reflect an arrow function to `ReflectionHost.getDefinitionOfFunction`. This will be useful for some upcoming work.

PR Close #50084
2023-05-04 08:56:24 +02:00
Andrew Kushnir
2180a692b0 refactor(core): minor updates to TestBed error messages (#50072)
This commit updates TestBed error messages to avoid using `R3TestBed` reference and just use `TestBed` instead.

PR Close #50072
2023-05-04 08:53:04 +02:00
Matthieu Riegler
a1ca162fd6 docs(docs-infra): Remove unused annotation template (#50114)
This page is unused since v7.

PR Close #50114
2023-05-03 10:39:49 +02:00
Matthieu Riegler
8741670a2d docs: Make links out of @see tags (#50098)
This commit is part of the work for #50097 to improve the linking on the online documentation.

PR Close #50098
2023-05-02 13:14:25 +02:00
Matthieu Riegler
3c474485e2 docs: Add rxjs-interop and reactivity primitives APIs (#50066)
This commit add the APIs of rxjs-interop and reactivity primitives to the online documentation.

PR Close #50066
2023-05-01 07:53:47 -07:00
Alan Agius
06452af31f fix(platform-server): remove dependency on @angular/platform-browser-dynamic (#50064)
Using `@angular/platform-browser-dynamic` is no longer required for JIT scenarios with Ivy. Instead `@angular/compiler` should be imported instead.

This change is part of the effort to reduce the server bundles sizes, which is needed to support cloud workers.

BREAKING CHANGE:
Users that are using SSR with JIT mode will now need to add  `import to @angular/compiler` before bootstrapping the application.

**NOTE:** this does not effect users using the Angular CLI.

PR Close #50064
2023-05-01 07:50:03 -07:00
Matthieu Riegler
f49c6d0a2f refactor(common): Deprecate useless isPlatform functions (#50055)
The Web worker platform was removed in v11.
`isPlatformWorkerApp` & `isPlatformWorkerUi` have no purpose since.

PR Close #50055
2023-05-01 07:39:40 -07:00
Alex Rickabaugh
cc89766cee refactor(core): finalize rxjs-interop options & docs (#50071)
This commit introduces an interface for `toSignal` options to mirror that of
`toObservable`, and adjusts docs for both symbols. It also adds the ability
for `toSignal` to manually specify `DestroyRef` (similarly to
`toObservable` accepting an injector) or for `toSignal` automatic cleanup to
be disabled (in which case the subscription persists until the Observable
completes). Either option allows `toSignal` to be used outside of a DI
context, like `toObservable`.

PR Close #50071
2023-04-28 16:08:47 -07:00
Leosvel Pérez Espinosa
cfab3ad706 refactor(compiler-cli): add back ngcc as a no-op with a warning (#50045)
This commit adds back `ngcc` as a no-op operation. When invoked it will warn providing details about removing `ngcc`.

In Angular 17, this will be removed.

PR Close #50045
2023-04-28 18:18:40 +02:00
Andrew Scott
ce00738f98 fix(compiler-cli): catch fatal diagnostic when getting diagnostics for components (#50046)
This commit adds similar handling to what was done in ed817e32fe.
The language service calls the `getDiagnosticsForComponent` function
when the file is not a typescript file.

fixes https://github.com/angular/vscode-ng-language-service/issues/1881

PR Close #50046
2023-04-28 15:18:03 +02:00
Matthias Kunnen
5a37928bab fix(common): fix incorrectly reported distortion for padded images (#49889)
The original code uses clientWidth and clientHeight which returns the
width and height of the element including the padding. This results in
the aspect ratio being determined incorrectly and the image distortion
warning triggering. The new code uses getComputedStyle which returns
the width and height without padding.

Another advantage of using getComputedStyle is that, unlike clientWidth
and clientHeight, the number returned is a decimal which provides
greater accuracy. This could allow for lowering the ASPECT_RATIO_TOLERANCE.

PR Close #49889
2023-04-27 17:16:46 +02:00
Matthias Kunnen
f9cee4db83 test(common): test rounding problems in image distortion detection (#49889)
Due to assertNoImageDistortion using clientWidth and clientHeight, and these properties returning integers, rounding errors occur that exceed the aspect ratio tolerance.
Increasing the tolerance could hide actual distortion so correcting the calculation to use floats would be best and could even allow for a lower tolerance.

PR Close #49889
2023-04-27 17:16:46 +02:00
Matthias Kunnen
857cf7ea23 test(common): show ngOptimizedImage distortion detection failure on padded images (#49889)
The image distortion detection performed uses clientWidth/clientHeight which includes the padding.
This leads to images with padding being detected as distorted while they are not and distortion being masked by padding.

PR Close #49889
2023-04-27 17:16:46 +02:00
Andrew Scott
567123499a refactor(core): Add signal LView flag (#49988)
This commit adds an LView flag to indicate that a view is a "signal"
view and updates view creation code to correctly set the flag
based on the declaration component metadata.

PR Close #49988
2023-04-27 00:33:57 -07:00
Andrew Scott
599f339582 refactor(core): separate render and change detection instructions (#50017)
Both the render and update instructions live in the same file and are
only separated via a "render*" vs "refresh*" naming convention. This
commit moves these functions to completely separate files.

PR Close #50017
2023-04-26 23:49:06 -07:00
Andrew Scott
a8cf5962ef refactor(core): Rename 'transplanted' view refresh flag and counters to be generic (#50000)
It's likely that the flag and counters used to track transplanted views
needing a refresh will be reused to signal views as well. The two follow
a similar rule: While the parents might not be "Dirty", there is still a
child/descendant view somewhere that needs to be refreshed during change
detection.

PR Close #50000
2023-04-26 11:29:48 -07:00
Andrew Kushnir
744f7ffb61 refactor(platform-server): avoid using platformDynamicServer when ngJitMode is disabled (#50007)
This commit refactors the logic of the `platform-server` to avoid using `platformDynamicServer` when `ngJitMode` is disabled. This is needed to avoid including JIT compiler into the source code of the server bundle, when this compil
er is not needed.

PR Close #50007
2023-04-26 09:23:52 -07:00
Alan Agius
74194de6f9 fix(platform-browser): export deprecated TransferState as type (#50015)
Prior to this commit `TransferState` re-export could not be used as a type.

Closes #50014

PR Close #50015
2023-04-26 09:21:07 -07:00
Matthieu Riegler
08949c7c6c refactor(core): Error code for Component Id collision (#49986)
The commit add an error code for the Component Id collision and documentation page to fix the issue.

PR Close #49986
2023-04-26 09:19:58 -07:00
Andrew Scott
8fdc116542 refactor(core): Use bit shift operator instead of manually writing numbers (#49987)
The LViewFlags are using manually written 0bxxxxx numbers which can be very hard to read
once there are more than a handful of 0s and 1s. The bit shifting feels a lot more
legible.

PR Close #49987
2023-04-25 17:23:28 -07:00
Andrew Scott
5214df4958 refactor(compiler-cli): Add signals to internal directive metadata (#49981)
This commit adds the `signals: boolean` property to the internal
directive/component metadata. This does not add it to the public API
yet, as the feature has no internal support other than compiler
detection.

PR Close #49981
2023-04-25 15:39:18 -07:00
Matthieu Riegler
8a2739f250 build(elements): remove unecessary filegroup. (#49982)
This is uneccessary now. All supported browsers support custom elements.

PR Close #49982
2023-04-25 09:30:59 -07:00
Jessica Janiuk
1090bf870f refactor(core): improve error message when dom node is not found (#49977)
This adds context to the error message in the case that a DOM node is not found during the hydration process. It outputs the expected DOM structure based on the lView and tNode rather than an unhelpful text message.

PR Close #49977
2023-04-25 09:29:47 -07:00
Andrew Scott
02a539cb14 refactor(core): Synchronously emit the current signal value in toObservable (#49894)
As described in
https://github.com/angular/angular/discussions/49681#discussioncomment-5628930,
if an `Observable` created from a signal with `toObservable` is
subscribed to in a template, it will initially have `null` as the value.
Immediately after the template is done executing, effects are flushed
and this results in the `AsyncPipe` getting a new value before the
`checkNoChanges` pass, resulting in `ExpressionChanged` error.

```
template: '{{obs$ | async}}'
...
obs$ = toObservable(signal(0));
```

Instead, this commit updates the `toObservable` to synchronously emit
the initial value to the Observable stream.

Side note here: We don't exactly encourage this pattern. Instead of
using `AsyncPipe`, the template should just read signals.

PR Close #49894
2023-04-25 09:27:38 -07:00
Matthieu Riegler
5607e0f529 fix(core): typing of TestBed Common token. (#49997)
Both `ComponentFixtureAutoDetect`  and `ComponentFixtureNoNgZone` are mistyped. Tokens are only instantiated with booleans.

PR Close #49997
2023-04-25 09:27:08 -07:00
Matthieu Riegler
e5801be1b2 refactor(core): call publishSignalConfiguration when bootstraping a standalone component. (#49968)
`publishSignalConfiguration` was not called when bootstraping an app using `boostrapApplication()`

PR Close #49968
2023-04-24 11:54:04 -07:00
Matthieu Riegler
b9c53658a4 refactor(compiler-cli): remove unecessary type assertion (#49971)
microsoft/TypeScript#43966 was fixed in 4.3.1

PR Close #49971
2023-04-24 11:51:18 -07:00
Jessica Janiuk
ec62f426b1 test(core): Add hydration symbols test (#49955)
Add symbols tracking test for hydration.

PR Close #49955
2023-04-24 09:57:52 -07:00
Jessica Janiuk
be104ec6ed fix(core): add newline to hydration mismatch error (#49965)
This adds a newline after the hydration mismatch errors to provide more separation and readability.

PR Close #49965
2023-04-24 09:52:45 -07:00
Matthieu Riegler
bb6a3e849e refactor(core): throw an error when APP_INITIALIZER token is not an array. (#49860)
Providing a non-multi token for `APP_INITIALIZER` now throws `INVALID_MULTI_PROVIDER` (NG209)

PR Close #49860
2023-04-23 18:31:24 -07:00
Andrew Kushnir
3bcbfecb78 refactor(platform-browser): log a warning when a custom or a noop ZoneJS is used with hydration (#49944)
Hydration relies on a signal from ZoneJS when it becomes stable inside an application, so that Angular can start serialization process on the server or post-hydration cleanup on the client (to remove DOM nodes that remained unclaimed).

Providing a custom or a "noop" ZoneJS implementation may lead to a different timing of the "stable" event, thus triggering the serialization or the cleanup too early or too late. This is not yet a fully supported configuration.

This commit adds a warning (non-blocking) for those cases.

PR Close #49944
2023-04-23 18:23:28 -07:00
Matthieu Riegler
2487d41bbf docs: remove mention of the webworker platform issues (#49947)
The Webworker platform was remove in v10, we can remove this part.

Fixes #49934

PR Close #49947
2023-04-23 18:20:58 -07:00
Payam Valadkhan
345dd6d81a refactor(compiler-cli): Add experimental local compilation mode. (#49846)
In this mode the compiler generates code based on each individual source file without using its dependencies. This mode is suitable only for fast edit/refresh during development.

PR Close #49846
2023-04-23 18:19:35 -07:00
Andrew Kushnir
bbc2efcda2 refactor(core): hydrate components of the same type used with and without ngSkipHydration (#49943)
This commit updates hydration logic to hanlde a case when the same component is used multiple times in a template and in some of those cases, component is opted-out of hydration, for example:

```
<cmp ngSkipHydration />
<cmp />
```

Previously, the first occurrence of the `<cmp>` would result in storing the `ssrId` on a TView as `null` (since hydration is disabled for the component) and the second component instance reused the `null` as a value, thus also skipping hydration.

With the changes from this commit, the `ssrId` would be set when we come across a hydratable instance. We also make sure that the `ssrId` value never changes after we first set it to a non-`null` value.

PR Close #49943
2023-04-20 14:50:32 -07:00
skrtheboss
c029c678d9 fix(core): ensure takeUntilDestroyed unregisters onDestroy listener on unsubscribe (#49901)
The takeUntilDestroyed must always remove the onDestroy listener,
in the teardown logic.

PR Close #49901
2023-04-19 19:55:09 +00:00
Pawel Kozlowski
1dc919a3df fix(core): execute query setters in non-reactive context (#49906)
This commit assures that query results setters run when there is no active
reactive consumer set.

PR Close #49906
2023-04-19 18:12:15 +00:00
Pawel Kozlowski
40318021ee fix(core): execute input setters in non-reactive context (#49906)
This change explicitly resets a reactive consumer before setting inputs
on directive instances. This is to assure that any potential input setters
do _not_ run in the reactive context.

PR Close #49906
2023-04-19 18:12:15 +00:00
Kristiyan Kostadinov
9165942629 fix(core): handle invalid classes in class array bindings (#49924)
When binding an array to `class` like `[class]="['foo', 'bar']"`, the runtime treats it the same as a literal binding with all the values being `true`, e.g. `{foo: true, bar: true}`. While object literals can only have string keys, arrays can have any value which can lead to errors if the array contains non-string values.

These changes add some logic to stringify the keys and ignore invalid ones.

Fixes #48473.

PR Close #49924
2023-04-19 16:28:26 +00:00