Commit graph

9842 commits

Author SHA1 Message Date
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
Matthieu Riegler
195aaa6b11 refactor(core): Create TestBed injector without a module (#49864)
We can create the injector without relying on th module factory.

PR Close #49864
2023-04-19 15:30:23 +00:00
Andrew Kushnir
338c7d9125 test(core): adding extra tests for hydration of view containers located after <ng-content> slots (#49920)
This commit adds extra tests to verify a couple additional use-cases related to view containers located after <ng-content> slots.

PR Close #49920
2023-04-19 14:26:43 +00:00
Andrew Kushnir
81ef9c327d refactor(core): handle empty projection slots within <ng-container> during hydration (#49920)
This commit updates hydration logic to handle cases when there are projection slots present in a template inside of an `<ng-container>` and when there are regular elements follow an <ng-content> slot (see tests for additional information). With this combination, the logic that annotates regular element locations should fallback to calculating a path from a reference node to that node. In case of an <ng-container>, the comment node is located *after* the node that needs an annotation. An existing logic was mistakenly returning an empty path, which was represented as a pointer to teh reference node. This commit fixes that and triggers a fallback to using a component host node as a reference in this case.

Resolves #49918.

PR Close #49920
2023-04-19 14:26:43 +00:00
Alan Agius
efb3c68899 refactor(core): remove redundant hydrationInfo check (#49926)
This check is not needed as it is done in the previous line

PR Close #49926
2023-04-19 14:21:40 +00:00
Angular Robot
50de000cf7 build: update dependency google-closure-compiler to v20230411 (#49892)
See associated pull request for more information.

PR Close #49892
2023-04-18 19:07:14 +00:00
Andrew Kushnir
5efd4fff57 refactor(core): insert special marker only when text node content is an empty string (#49877)
Empty text nodes are not present in the server-rendered HTML output, thus we inject a special marker
at a text node location to later restore an empty text node at the client. Currently, we treat text nodes with spaces as "empty" as well, however those spaces are present in the HTML and text nodes are created in a browser. Adding extra annotation in this case results in extra text nodes created on the client and may trigger hydration issues. This commit updates the code to avoid treating text nodes with spaces as "empty".

PR Close #49877
2023-04-18 19:04:28 +00:00
Alex Rickabaugh
0d9705be0b refactor(compiler): next context merging in the template pipeline (#49797)
This commit adds a phase to the template pipeline to merge `nextContext()`
instructions that follow each other without context reads in between. That
is, the sequence:

```typescript
nextContext();
var v1 = nextContext();
```

becomes:

```typescript
var v1 = nextContext(2);
```

PR Close #49797
2023-04-18 17:00:51 +00:00
Alex Rickabaugh
73c03ebc1b refactor(compiler): convert literals and this in template pipeline (#49797)
This commit adds support for two new expression AST forms to the template
pipeline ingest step: literal values and `this`.

PR Close #49797
2023-04-18 17:00:51 +00:00
Alex Rickabaugh
227d18f64a refactor(compiler): emit correct listener name in template pipeline (#49797)
This commit modifies the `ListenerOp` operation to capture the context
needed to generate the "correct" (per `TemplateDefinitionBuilder`) function
name for the handler function for the listener.

PR Close #49797
2023-04-18 17:00:51 +00:00
Alex Rickabaugh
d742e61621 refactor(compiler): fix wrong instruction emit for resetView (#49797)
The `resetView` instruction in the template pipeline had a copy-paste error
where it was emitting a call to `reference` instead. This commit fixes the
issue.

PR Close #49797
2023-04-18 17:00:51 +00:00
Alex Rickabaugh
e98d1fee3e refactor(compiler): implement operation chaining in the template pipeline (#49797)
This commit adds a chaining phase which post-processes reified template
pipeline operations, and collapses chainable instructions into chained
calls. Performing chaining as a post-processing step after reification
allows the specifically selected instruction variants to be known when
considering chaining two operations.

PR Close #49797
2023-04-18 17:00:51 +00:00
Alex Rickabaugh
4000085a3e refactor(compiler): variable optimizer for the template pipeline (#49797)
This commit adds a variable optimization pass to the template pipeline. The
pipeline generates all variables which might be referenced within a given
view's template function, regardless of whether other operations will read
those values.

The variable optimizer post-processes the IR and performs several variable-
related optimizations:

* It transforms variable declarations to side effectful expressions when the
  variable is not used, but its initializer has global effects which other
  operations rely upon.
* It removes variable declarations if those variables are not referenced and
  either they do not have global effects, or nothing relies on them.
* It inlines variable declarations when those variables are only used once
  and the inlining is semantically safe.

PR Close #49797
2023-04-18 17:00:51 +00:00
Alex Rickabaugh
b20d630054 refactor(compiler): handle textInterpolate with empty string bookends (#49797)
This commit teaches the template pipeline how to generate `textInterpolate`
when there's a single expression with no surrounding static text.

PR Close #49797
2023-04-18 17:00:50 +00:00
Alex Rickabaugh
f929617932 refactor(compiler): reorder constant pool statements in template pipeline (#49797)
This commit reverses the generate template functions when adding them to the
constant pool in the template pipeline. This seems to better match the
ordering in which `TemplateDefinitionBuilder` generates template functions.
Further study is needed to determine if this is exactly accurate.

PR Close #49797
2023-04-18 17:00:50 +00:00
Alex Rickabaugh
e386e22e6e refactor(compiler): skip emit of empty blocks in template pipeline (#49797)
This commit configures the template pipeline to skip the emit of empty
create or update blocks of a template function.

PR Close #49797
2023-04-18 17:00:50 +00:00
Alex Rickabaugh
b0ba884ab0 refactor(compiler): fix issues with advance() in the template pipeline (#49797)
`advance()` was not emitted correctly by the template pipeline. There were
two problems:

* it was not handled in `transformExpressionsInOp()`.
* it was not added to the list correctly in `phaseGenerateAdvance()`.

This commit addresses both problems.

PR Close #49797
2023-04-18 17:00:50 +00:00