Commit graph

3934 commits

Author SHA1 Message Date
Alex Castle
dde3fdabbd feat(common): upgrade warning to logged error for lazy-loaded LCP images using NgOptimizedImage (#52004)
Upgrade the existing warning so it now logs an error instead, when an LCP element is determined to not be usings the `priority` attribute. Error is logged, not thrown.

PR Close #52004
2023-10-04 11:36:01 -07:00
Joey Perrott
5269cae788 build: lock file maintenance (#51834)
Update the lock file.

PR Close #51834
2023-10-04 11:31:27 -07:00
Andrew Kushnir
706838950c refactor(core): allow nested @defer block to contain the same dependency (#51964)
Currently, if there are 2 nested @defer blocks with the same dependency, Angular throws an error at runtime to indicate that there was a duplicate component def in the registry. This commit updates the logic to only append dependencies when they didn't previously exist in the registry.

PR Close #51964
2023-10-04 09:00:23 -07:00
Paul Gschwendtner
9b9e11fcaf refactor(core): deprecate allowing full context object to be replaced in EmbeddedViewRef (#51887)
This partially reverts commit a3e17190e7
and deprecates behavior added.

The context of an embedded view ref at some point was switched from a
getter to an actual assignable property. This is something we revert
as it introduces additional complexity for our generated code
(in terms of closures capturing the `ctx`), creates technical
limitations for Angular's internals and the usage pattern is rarely
used (and can be addressed via simple assignments, `Object.assign` or
the use of a proxy if replacing the full context object is still
desirable)

DEPRECATED: Swapping out the context object for `EmbeddedViewRef`
is no longer supported. Support for this was introduced with v12.0.0, but
this pattern is rarely used. There is no replacement, but you can use
simple assignments in most cases, or `Object.assign , or alternatively
still replace the full object by using a `Proxy` (see `NgTemplateOutlet`
as an example).

Also adds a warning if the deprecated

PR Close #51887
2023-10-04 08:14:35 -07:00
Andrew Scott
d77c4b2aae 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:13 -07:00
Kristiyan Kostadinov
8e7feefb5b build: align schematics tsconfig with rest of the project (#51969)
Adds `noPropertyAccessFromIndexSignature` to the tsconfig of the schematics in order to align it with the rest of the project.

PR Close #51969
2023-10-04 07:28:41 -07:00
Andrew Kushnir
650ab4f218 refactor(core): add support for on timer trigger in @defer blocks (#51974)
This commit adds the logic to support `on timer` triggers in `@defer` blocks in both rendering and prefetching conditions.

PR Close #51974
2023-10-04 07:27:45 -07:00
Pawel Kozlowski
7d42dc3c02 feat(core): the new list reconciliation algorithm for built-in for (#51980)
This commit plugs the new list reconciliation into the new built-in repeater.

PR Close #51980
2023-10-03 19:40:35 -07:00
Pawel Kozlowski
4f04d1cdab feat(core): add new list reconcilation algorithm (#51980)
The new list reconcilation algorithm, an alternative to
the DefaultIterableListDiffer. It works by performing updates
in place instead of creating intermediate data describing changes
to apply. For lists expressed as an Array it performs additional
optimizations for the moves and swap scenarios.

The new list diffing approach is meant to be used in the new control
flow and should me much faster as compared to the ngFor with the
DefaultIterableListDiffer.

PR Close #51980
2023-10-03 19:40:35 -07:00
Dylan Hunn
07602eb298 refactor(compiler): Implement basic support for defer in Template Pipeline (#51942)
The template pipeline now supports basic forms of `defer` blocks. This includes the `loading`, `placeholder`, and `error` blocks, as well as the loading and placeholder configuration options.

Lazy dependencies and prefetch are not yet implemented.

PR Close #51942
2023-10-03 19:40:04 -07:00
Kristiyan Kostadinov
43e6fb0606 feat(core): enable block syntax (#51994)
Enables the new `@` block syntax by default by removing the `enabledBlockTypes` flags. There are still some internal flags that allow special use cases to opt out of the block syntax, like during XML parsing and when compiling older libraries (see #51979).

PR Close #51994
2023-10-03 15:26:05 -07:00
Dylan Hunn
489ec15e1d refactor(compiler): Fix pipeBinding variable offsets in template pipeline (#51961)
This is a deceptively simple fix for a deep issue. Consider the following template:

```
<button [title]="myTitle" [id]="(auth().identity() | async)" [tabindex]="1">
```

`TemplateDefinitionBuilder` allocates the following variable (binding) slots:

v[0] = [title] binding
v[1] = [id] binding
v[2] = [tabindex] binding
v[3] = pipe binding
v[4] = pipe binding

As you can see, all three top-level property bindings were assigned variable indices. Then, variables for nested expressions were assigned.

Before this change, Template Pipeline would choose the following order:

v[0] = [title] binding
v[1] = [id] binding
v[2] = pipe binding
v[3] = pipe binding
v[4] = [tabindex] binding

With this order, nested expressions have their variables counted and assigned before subsequent top-level property bindings. This results in different variable indices for `pipeBinding` expressions that are not inside the final property binding.

However, this is not just different -- it's actually incorrect! Consider a case like the following:

```
<button [p1]="c ? (a | pipe) : 3" [p2]="b | pipe">
```

These pipe bindings are executed *conditionally*. This means that, because we don't count and assign all the "fixed" variable slots first, i.e. those belonging to the property bindings, their indices might end up incorrect, depending on whether or not a pipeBinding happened as part of the update block.

With this change, we count all variables on top-level ops first, and then descend into all expressions.

PR Close #51961
2023-10-02 16:58:03 -07:00
Kristiyan Kostadinov
5419af6192 build: fix compilation error due to conflict (#51981)
Fixes a compilation error that happened, because a couple of related PRs landed at the same time.

PR Close #51981
2023-10-02 10:55:46 -07:00
Kristiyan Kostadinov
4f69d620d9 fix(core): deferred blocks not removing content immediately when animations are enabled (#51971)
Fixes an issue where if animations are enabled, deferred blocks don't remove their placeholder blocks immediately from the DOM. The problem is that we register the event handlers in `afterRender` which runs outside the zone, but the logic that removes the DOM nodes during animations is tied to change detection.

These changes resolve the issue by binding the listeners inside the zone. This was the intention from the beginning, I just forgot that `afterRender` runs outside the zone.

Fixes #51970.

PR Close #51971
2023-10-02 09:12:48 -07:00
Andrew Kushnir
367b075d15 test(core): enable previously failing @defer tests (#51965)
This commit re-enables previously flaky tests. The original issue was resolved by mocking `requestIdleCallback` in tests.

PR Close #51965
2023-10-02 08:35:51 -07:00
Andrew Kushnir
e368d81896 refactor(core): invoke @defer (on idle) callback in NgZone (#51975)
Currently, there is no change detection scheduled after triggering `on idle` condition, since `requestIdleCallback` is not patched by Zone.js. This commit invokes the callback in NgZone, so that the code that is invoked within the callback can use zones and a new change detection round is scheduled as needed.

Fixes #51973.

PR Close #51975
2023-10-02 08:35:07 -07:00
AleksanderBodurri
a54713c831 feat(core): implement ɵgetInjectorMetadata debug API (#51900)
This API allows for inspection of a given injector to determine it's type (Element, Environment, Null) as well as it's "source".

- For Environment injectors the source is the source of the injector; `injector.source`.
- For Element injectors the name is the DOM Element that created the injector.
- For the Null Injector this is the string `"Null Injector"`.

PR Close #51900
2023-09-29 15:22:34 -07:00
Andrew Kushnir
6b6a44c473 refactor(core): add hydration support for built-in for (#51920)
This commit adds hydration support for repeaters (for loops) and empty blocks. The logic looks up a dehydrated view and use this information for hydration. Otherwise, DOM elements for a view are created from scratch.

PR Close #51920
2023-09-29 15:21:21 -07:00
Matthieu Riegler
e753278faa feat(animations): Add the possibility of lazy loading animations code. (#50738)
`provideLazyLoadedAnimations()` returns providers which allow the lazy loading of the animation module.

Lazy loading of the animation code can shave off up to 16KB gzipped of the main bundle.

PR Close #50738
2023-09-29 10:49:39 -07:00
Kristiyan Kostadinov
e2e3d69a27 feat(core): support deferred triggers with implicit triggers (#51922)
Adds support for defining `viewport`, `interaction` and `hover` triggers with no parameters. If the framework encounters such a case, it resolves the trigger to the root element of the `@placeholder` block. Triggers with no parameters have the following restrictions:
1. They have to be placed on an `@defer` block that has an `@placeholder`.
2. The `@placeholder` can only have one root node.
3. The root placeholder node has to be an element.

PR Close #51922
2023-09-27 12:59:34 -07:00
Alan Agius
8413b64a6b refactor(core): add whenStable private API (#51807)
Prior to this change `this.isStable.pipe(first((isStable) => isStable)).toPromise()` had to be done in multiple places across the framework and the Angular CLI see https://github.com/angular/angular-cli/pull/25856#discussion_r1328158846. In the majority of cases an Observable based `isStable` API is not needed. This also removes the need for RXJS operator imports.

PR Close #51807
2023-09-27 10:31:56 -07:00
Andrew Kushnir
7a731c9536 refactor(core): add hydration support for built-in if and switch (#51915)
This commit updates the `if` and `switch` logic to support hydration. The logic attempts to find dehydrated views in containers while processing `if` and `switch` instructions. If a dehydrated is found, its used to further match elements. Otherwise, DOM elements for a view are created from scratch.

PR Close #51915
2023-09-27 10:29:07 -07:00
Andrew Kushnir
f483aed86a refactor(core): populate dehydrated views in template instruction (#51915)
Previously, dehydrated views lookup was triggered only when ViewContainerRef was injected. The new control flow logic uses lower level APIs, thus having the code only in the ViewContainerRef is not sufficient.

This commit adds the logic to invoke the process of dehydrated views lookup from the `template` instruction, thus enabling it for new control flow instructions as well.

PR Close #51915
2023-09-27 10:29:07 -07:00
Andrew Kushnir
a39010f6ce 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:48 -07:00
Alan Agius
ba0effd494 refactor(migrations): rename migration to remove version prefix (#51926)
The version prefix in the migration name is redundant.

PR Close #51926
2023-09-27 09:20:00 -07:00
Alan Agius
e66c18ffa0 refactor(migrations): remove unused version 16 migrations (#51926)
When updating to version 17, version 16 migrations cannot be executed thus making them redundant to have in the package.

PR Close #51926
2023-09-27 09:20:00 -07:00
Kristiyan Kostadinov
c7127b98b5 feat(core): add schematic to escape block syntax characters (#51905)
#51891 introduces a new syntax that assigns a new meaning to the `@` and `}` in Angular templates. This is problematic for existing apps which may have the characters in their templates already, because it can lead to syntax errors.

These changes add an `ng update` schematic that will replace any usages of the special characters with their HTML entities.

PR Close #51905
2023-09-26 15:23:49 -07:00
Kristiyan Kostadinov
31295a3cf9 fix(compiler): allocating unnecessary slots in conditional instruction (#51913)
Fixes that we were allocating slots for the expressions of `if`, `else if`, `switch` and `case` blocks which we weren't using for anything.

PR Close #51913
2023-09-26 15:22:49 -07:00
Andrew Kushnir
4b38e9a1ab refactor(core): add batching for defer blocks with on idle conditions (#51750)
This commit updates runtime logic of defer blocks to schedule a single `requestIdleCallback` for a group of defer blocks created within a single change detection cycle (for example, as a result of a defer block being defined in a for loop).

PR Close #51750
2023-09-26 15:20:34 -07:00
Kristiyan Kostadinov
8be2c48b7c feat(core): implement new block syntax (#51891)
Switches the syntax for blocks from `{#block}{/block}` to `@block {}` based on the feedback from the community.

Read more about the decision-making process in our blog: https://blog.angular.io/meet-angulars-new-control-flow-a02c6eee7843

The existing block types changed in the following ways:

**Conditional blocks:**
```html
<!-- Before -->
{#if cond}
  Main content
  {:else if otherCond}
    Else if content
  {:else}
    Else content
{/if}

<!-- After -->
@if (cond) {
  Main content
} @else if (otherCond) {
  Else if content
} @else {
  Else content
}
```

**Deferred blocks**
```html
<!-- Before -->
{#defer when isLoaded}
  Main content
  {:loading} Loading...
  {:placeholder} <icon>pending</icon>
  {:error} Failed to load
{/defer}

<!-- After -->
@defer (when isLoaded) {
  Main content
} @loading {
  Loading...
} @placeholder {
  <icon>pending</icon>
} @error {
  Failed to load
}
```

**Switch blocks:**
```html
<!-- Before -->
{#switch value}
  {:case 1}
    One
  {:case 2}
    Two
  {:default}
    Default
{/switch}

<!-- After -->
@switch (value) {
  @case (1) {
    One
  }

  @case (2) {
    Two
  }

  @default {
    Default
  }
}
```

**For loops**
```html
<!-- Before -->
{#for item of items; track item}
  {{item.name}}
  {:empty} No items
{/for}

<!-- After -->
@for (item of items; track item) {
  {{item.name}}
} @empty {
  No items
}
```

PR Close #51891
2023-09-26 09:10:04 -07:00
Andrew Kushnir
487b9e118a test(core): disable flaky tests temporarily (#51895)
This commit disables a couple newly-added tests related to `on idle` trigger condition for @defer blocks. Tests would be re-enabled back once we identify the reason of flakiness and fix it.

PR Close #51895
2023-09-25 16:48:46 -07:00
Andrew Kushnir
baaaa6daf6 refactor(core): add on immediate support for defer blocks (#51630)
This commit adds a logic to handle `on immediate` conditions both as a main condition, as well as a prefetching condition (i.e. `prefetch on immediate`).

PR Close #51630
2023-09-25 09:17:55 -07:00
Kristiyan Kostadinov
16f5fc40a4 feat(core): support deferred viewport triggers (#51874)
Adds support for `on viewport` and `prefetch on viewport` triggers which will load the deferred content when the element comes into the view.

PR Close #51874
2023-09-25 09:17:03 -07:00
Kristiyan Kostadinov
687b96186c feat(core): support deferred hover triggers (#51874)
Adds support for `on hover` and `prefetch on hover` triggers. Some code had to be moved around so it could be reused from the `on interaction` triggers.

PR Close #51874
2023-09-25 09:17:03 -07:00
Kristiyan Kostadinov
3cbb2a8ecf feat(core): implement deferred block interaction triggers (#51830)
Adds the implementation for the `on interaction` and `prefetch on interaction` triggers.

PR Close #51830
2023-09-22 12:17:54 -07:00
Kristiyan Kostadinov
00e6013661 refactor(compiler): implement final instruction generation for interaction triggers (#51830)
Updates the logic that generates the instructions for the `on interaction` and `prefetch on interaction` triggers to their final shape. Now the instructions take two arguments:
1. `triggerIndex` - index at which to find the trigger in the view where it will be rendered.
2. `walkUpTimes` - tells the runtime how many views up it needs to go to find the trigger element. If the argument is omitted, it means that the trigger is in the same view as the deferred block. A positive number means that the runtime needs to go up X amount of times to find the trigger. A negative number means that the trigger is inside the root view of the placeholder block. Negative numbers are capped at -1 since the placeholder is always in the same position at runtime.

PR Close #51830
2023-09-22 12:17:54 -07:00
Matthieu Riegler
0598613950 refactor(animations): deprecation of AnimationDriver.NOOP (#51843)
The `NoopAnimationDriver` as static property of `AnimationDriver` prevents it from being removed by tree shaking. This commit deprecates it and exposes the `NoopAnimationDriver` on the public API to replace its usage.

DEPRECATED:
The `AnimationDriver.NOOP` symbol is deprecated, use `NoopAnimationDriver` instead.

PR Close #51843
2023-09-22 12:15:45 -07:00
Matthieu Riegler
6610c4fb10 refactor(core): Use the Writable type when overwriting readonly properties. (#49754)
The `Writable` type is usefull when we want overwrite readonly properties and we still want to maintain code navigation/reference. It should be use instead of `any` type assertions for example.

PR Close #49754
2023-09-22 10:02:13 -07:00
Matthieu Riegler
ca416b57a8 refactor(core): Private export of the Writable type (#49754)
The `Writable` type is usefull when we want overwrite readonly properties and we still want to maintain code navigation/reference. It should be use instead of `any` type assertion for example.

PR Close #49754
2023-09-22 10:02:13 -07:00
Andrew Kushnir
4599642a87 docs: annotate ComponentFixture.getDeferBlocks as a developer preview API (#51855)
PR Close #51855
2023-09-22 09:52:13 -07:00
Payam Valadkhan
077534ef0f refactor(core): enabled using deps tracker in JIT compilation (#51415)
This change simply flip the flag which enables using the deps tracker in JIT compilation (the logic is already implemented in a previous PR). Some tests which depend on the old JIT implementation (e.g., patching the scope info into the type) are modified accordingly.

PR Close #51415
2023-09-22 09:49:33 -07:00
Payam Valadkhan
654d6ce2fa refactor(core): remove class type check when clearing cache in deps tracker (#51415)
Using verification helpers such as `isComponent` may trigger JIT compilation. Now in some tests such compilation is made purposely to fail, and so in such cases any reference to the `depsTracker.clearScopeCacheFor` method will cause the exception to be thrown earlier than expected which results in teh test failure. Such scenario is the case in the next commit when we enable using the deps tracker in the jit compilation. Note that such failure is only for the framework tests and is a very edge case. The tests in downstream apps will not lead to such scenario of failure at all.

PR Close #51415
2023-09-22 09:49:33 -07:00
Alan Agius
3c0577f991 perf(platform-browser): disable styles of removed components instead of removing (#51808)
This commit changes the behaviour of `REMOVE_STYLES_ON_COMPONENT_DESTROY`.

Now, `style` nodes are disabled instead of removed from DOM. This causes the same runtime behaviour but avoids recomputations when the stylesheet is re-added when the component is re-created. https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/css/css_style_sheet.h;l=266;drc=31fb07c05718d671d96c227855bfe97af9e3fb20

NB: This changes is being done following some performance bottlenecks observed in Phanteon and their own recommendations.

Context:
http://chat/room/AAAAxKxTk40/jaP6Lj6fhmQ/jaP6Lj6fhmQ
https://crbug.com/1444522
http://b/289992821

PR Close #51808
2023-09-22 09:48:35 -07:00
Pawel Kozlowski
dcf18dc74c fix(core): allow toSignal calls in reactive context (#51831)
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 #51831
2023-09-22 09:47:19 -07:00
Andrew Kushnir
917203d991 refactor(core): cleanup prefetch triggers when resource loading starts (#51856)
This commit adds the necessary mechanisms to perform cleanup of prefetch triggers when resource loading starts. Previously, this logic was missing, which resulted in retaining those triggers.

PR Close #51856
2023-09-22 09:46:52 -07:00
Payam Valadkhan
e3532291c7 refactor(core): print the errors related to computing component dependencies to the console in local compilation mode (#51824)
Certain tools in g3 which dynamically bootstrap a component (e.g., custom routers) simply swallow the exception coming from bootstrapping the component and show an empty outlet. Such cases are very difficult to debug as the dev has no clue why the component was not rendered. As bad as this pattern is, fixing all such tools for a better error handling is beyond the scope of our effort. Instead, in this change we print the error messages coming from calculating component dependencies (part of component rendering) to the console for a better visibility into the error. This change only affects local compilation where the component dependencies are calculated in runtime. This change can potentially shed light into many failures of local compilation in g3.

PR Close #51824
2023-09-20 12:25:40 +02:00
Payam Valadkhan
b44533ba39 refactor(core): include injector info for standalone components in local compilation mode (#51819)
Standalone component need to include the imported NgModules as part of their dependencies in order to be able to use the injection tokens coming from these NgModules. To do so, in this change the imported NgModules are included in the standalone component compilation scope.

PR Close #51819
2023-09-20 12:24:54 +02:00
Andrew Scott
ad61bf6184 refactor(router): Remove internal state tracking for browserUrlTree (#48065)
The browserUrlTree is only used to support the onSameUrlNavigation: 'ignore' logic. We can achieve this functionality without having this state tracked inside the Router. Instead, we can re-examine what ignore means: We don't want to rerun the matching logic, guards, or resolvers when we already know that nothing is changing.
Outside of the "navigated", there are two things that constitute a "change":

1. The browser URL might change. Because of skipLocationChange, the browser URL might not always match the internal state of the Router (we can navigate to a path but skip updating the browser URL). If we're navigating to a place that would change the browser URL, we should process the navigation. Theoretically, all we need to really do is update the browser URL instead of processing the whole navigation w/ guards, redirects, and resolvers. But this doesn't matter that much because the default value for runGuardsAndResolvers will skip all of this anyways.
2. The internal state of the Router might change. That is, we're navigating to a new path and may or may not be updating the updating the browser URL.

If either of the above are true, we process the navigation. If both are false, we aren't changing anything so we can safely ignore the navigation request (as long as onSameUrlNavigation === 'ignore').

Why is this change important?

* Simplification of Router internals. The Router has a lot of special case handling and one-offs to handle a limited set of scenarios. Removing these when possible makes the code easier to follow

PR Close #48065
2023-09-19 16:50:56 +02:00
Andrew Scott
0b3e6a41d0 fix(router): Remove malformedUriErrorHandler from ExtraOptions (#51745)
The `malformedUriErrorHandler` is used as a recovery mechanism for when the `UrlSerializer`
throws an error when parsing a URL string. If custom error handling is
desired for this, it should instead be done inside the
`UrlSerializer.parse` method itself. There's no reason to have an entire
feature option built around what can otherwise just be `try...catch`.

BREAKING CHANGE: `malformedUriErrorHandler` is no longer available in
the `RouterModule.forRoot` options. URL parsing errors should instead be
handled in the `UrlSerializer.parse` method.

PR Close #51745
2023-09-18 20:42:44 +02:00
Payam Valadkhan
873e80b869 refactor(core): fix NgModule compilation scope in deps tracker (#51791)
Currently deps tracker includes the exported scope of the exported NgModule only in the exported scope of that NgModule. This is in agreement with what AoT does today. But JIT diverges from this behavior by including these exported scopes into the compilation scope as well. Since deps tracker is going to be used for both AoT (local compilation mode) and JIT, the question might be which behavior the deps tracker should follow? Today it follows the AoT one, but it breaks some tests in Google which seem to depend on this behavior of JIT. So it is better to migrate deps tracker to what JIT does. This leads to a wider compilation scope in local compilation compared to full compilations, but it won't break any existing thing.

PR Close #51791
2023-09-18 17:00:31 +02:00