Commit graph

2367 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
ff0d23d6da refactor(core): cleanup references to dart (#49858)
The repo doesn't support dart anymore, we can reduce the references to it .

PR Close #49858
2023-04-18 14:00:45 +00:00
Pawel Kozlowski
b7392f9064 fix(core): execute template creation in non-reactive context (#49883)
This fix assures that templates functions executed in the creation mode
are run outside of the reactive context. This avoids the situation where
signal reads in a directive constructor (executed as part of the creation
mode) would mark the host component as dirty.

Fixes #49871

PR Close #49883
2023-04-18 13:59:42 +00:00
Jessica Janiuk
2845017f83 Revert "refactor(core): throw an error when APP_INITIALIZER token is not an array. (#49860)" (#49893)
This reverts commit bf2e11c035.

PR Close #49893
2023-04-17 18:57:47 +00:00
Matthieu Riegler
f3366c60e1 refactor(core): improve styling coverage (#49868)
The test was waiting for #34202 to be merged.

PR Close #49868
2023-04-17 14:02:40 +00:00
Matthieu Riegler
bf2e11c035 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-17 13:37:09 +00:00
Andrew Kushnir
d994f8520c fix(core): include inner ViewContainerRef anchor nodes into ViewRef.rootNodes output (#49867)
Currently, the `ViewRef.rootNodes` output is missing anchor (comment) nodes for inner `ViewContainerRef`s,
when an achor node was created for that instance of a `ViewContainerRef` (which happens in all cases except
when an <ng-container> was used as a host for a view container).

This issue affects hydration logic, which relies on the number of root nodes within a view to properly determine
segments in DOM that belong to a particular view.

Resolves #49849.

PR Close #49867
2023-04-17 13:35:58 +00:00
Matthieu Riegler
5715154461 refactor(core): Remove NG_DEV_MODE const (#49838)
Follow up to #49530, removing the last remaining `NG_DEV_MODE`

PR Close #49838
2023-04-14 14:12:53 +00:00
Andrew Scott
a26e6f6fa8 test(core): re-add tests for signals in OnPush components (#49836)
These tests were accidentally deleted during a rebase.

PR Close #49836
2023-04-14 14:12:23 +00:00
Pawel Kozlowski
2c22e6fb5f fix(core): onDestroy should be registered only on valid DestroyRef (#49804)
It might happen that the lifecycle scope represented by DestroyRef becomes
invalid before an onDestroy hook is registered (ex. injector or component
instance got destroyed). In such cases registration of the onDestroy hooks
should no longer be possible.

Fixes #49658

PR Close #49804
2023-04-13 21:14:44 +00:00
Pawel Kozlowski
2d0fcd611b refactor(core): add asReadonly helper to writable signals (#49802)
The new asReadonly method on the WritableSignal interface makes
it possible to create readonly instance of a writable signal.

Readonly signals can be accessed to read their value,
but can't be changed using set, update or mutate methods.

PR Close #49802
2023-04-13 20:48:12 +00:00
Matthieu Riegler
38fe1b91fc refactor(core): drop IE workarounds (#49763)
Angular doesn't support IE anymore. We can remove the workarounds related to IE.

Some workarounds are keep because of the support of domino but the comments related to IE are removed.

PR Close #49763
2023-04-13 14:01:45 +00:00
Pawel Kozlowski
ce38be03ce fix(core): allow async functions in effects (#49783)
This change makes is possible to use async functions
(ones returning a promise) as effect run functions.

To make it possible, the signature of the effect function
changed: effect cleanup function is registered now
(using a dedicated callback passed to the effect creation)
instead of being returned from the effect function.

PR Close #49783
2023-04-11 12:49:10 -07:00
De Wildt
ee816e171f revert "fixup! fix(router): fix = not parsed in router segment name" (#47332)
This reverts commit 2279f4d4620eba083a9832ed096890b69a25ec42.

Reverting that commit based off PR feedback that this change should only affect the parsing of sergments and node encoding of the url

PR Close #47332
2023-04-11 09:16:31 -07:00
dewildt
748c33ca6b fix(router): fix = not parsed in router segment name (#47332)
fix router segment name parsing to allow segements to container an unscaped = character. Currently if you have a url like /some-site/folder=/some-file then then middle segment "folder=" will stop parsing at the = sign and register that part of the path as just "folder"

Fixes #21381

PR Close #47332
2023-04-11 09:16:31 -07:00
Alan Agius
d37e21c582 refactor(animations): remove Domino specific logic (#49630)
These workarounds are no longer required following the fixes in https://github.com/angular/domino/pull/14/

PR Close #49630
2023-04-05 11:42:57 -07:00
Alan Agius
42f2f41f9e refactor(platform-browser): update renderer to be able to remove ServerRendererFactory2 and EmulatedEncapsulationServerRenderer2 (#49630)
This commits updates the render to able to handle the slight differences between platform-server and platform-browser.

This is needed to eventually be able to remove `ServerRendererFactory2` and `EmulatedEncapsulationServerRenderer2` from platform-server.

PR Close #49630
2023-04-05 11:42:57 -07:00
Alex Rickabaugh
10795288b0 refactor(core): add postSignalSetFn hook for WritableSignal (#49708)
This commit adds a hook to `WritableSignal` that is called whenever the
signal's value is updated via the mutation API. This hook allows consumers
to implement logic which is synchronous with signal sets (e.g. executing
effects). It's currently unused.

PR Close #49708
2023-04-05 11:10:09 -07:00
Pawel Kozlowski
df1dfc4c17 fix(core): make sure that lifecycle hooks are not tracked (#49701)
Angular lifecycle hooks should never be run as part of the reactive
context: we do not expect that signal reads in lifecycle hooks
report to any consumers.

In the current Angular some of the lifecycle hooks can be flushed
early, while executting template update pass. We need to make sure
that signal reads in those lifecycle hooks do not register as part
of the effect that marks components for check.
"

PR Close #49701
2023-04-05 10:48:22 -07:00
Andrew Scott
a4e749ffca fix(core): When using setInput, mark view dirty in same was as markForCheck (#49711)
`ComponentRef.setInput` internally calls `markDirtyIfOnPush` which only marks
the given view as dirty but does not mark parents dirty like `ChangeDetectorRef.markForCheck` would.
f071224720/packages/core/src/render3/instructions/shared.ts (L1018-L1024)

`markDirtyIfOnPush` has an assumption that it’s being called from the parent’s template. That is, we don’t need to mark dirty to the root, because we’ve already traversed down to it.
The function used to only be called during template execution for input
bindings but was added to `setInput` later. It's not a good fit because
it means that if you are responding to events such as an emit from an `Observable`
and call `setInput`, the view of your `ComponentRef` won't necessarily get checked
when change detection runs next. If this lives inside some `OnPush` component tree
that's not already dirty, it only gets refreshed if you also call
`ChangeDetectorRef.markForCheck` in the host component (because it will be "shielded" be a non-dirty parent).

PR Close #49711
2023-04-05 10:13:21 -07:00
Matthieu Riegler
3b863ddc1e refactor(core): Remove ReflectiveInjector symbol (#48103)
The `ReflectiveInjector` symbol has been deprecated in v5 (11 major versions ago). This commit removes ReflectiveInjector and related symbols.

BREAKING CHANGE: The `ReflectiveInjector` and related symbols were removed. Please update the code to avoid references to the `ReflectiveInjector` symbol. Use `Injector.create` as a replacement to create an injector instead.

PR Close #48103
2023-04-04 16:43:53 -07:00
Matthieu Riegler
1aef29ceb1 refactor(core): Cleanup for Iterable differs test. (#49598)
Remove some `any` and use the non-deprecated `Injector.create` overload.

PR Close #49598
2023-04-04 15:13:01 -07:00
Matthieu Riegler
061f3d1086 feat(core): Drop public factories property for IterableDiffers : Breaking change (#49598)
The `factories` property was marked as deprecated in v4 to make it private. Let's move it to private.

PR Close #49598
2023-04-04 15:13:01 -07:00
Andrew Scott
34b2d34d5b refactor(router): Remove RouterTestingModule in favor of RouterModule.forRoot (#49427)
`RouterTestingModule` is not needed as of v16. Instead, TestBed
automatically provides `MockPlatformLocation` in order to help test
navigations in the application. The location mocks in the
RouterTestingModule aren't necessary anymore.

There doesn't appear to be any real documentation around
`RouterTestingModule` other than the API docs.

PR Close #49427
2023-04-04 15:12:33 -07:00
Matthieu Riegler
41992a2979 refactor(core): remove #9100 todos. (#49408)
This commit includes a change on the `ViewRef.onDestroy` signature.

PR Close #49408
2023-04-04 15:01:48 -07:00
Guillaume Weghsteen
b35fa73968 feat(core): change the URL sanitization to only block javascript: URLs (#49659)
In modern browsers, the 'javascript:' URL scheme is the only scheme that
can execute JavaScript when passed in a navigation URL context (e.g.
`a.href` value). Validate URL shemes to only contain characters allowed
in the URL specification ([a-zA-Z-+.]), and that are not javascript
(case insensitive). This is not a breaking change. The URL sanitization
is loosen.

PR Close #49659
2023-04-04 15:01:13 -07:00
Matthieu Riegler
b2327f4df1 feat(core): Allow typeguards on QueryList.filter (#48042)
To match the behaviour of Array.filter, typeguards can now be used on QueryList.filter to narrow the return type.

Fixes #38446

BREAKING CHANGE: QueryList.filter now supports type guard functions, which will result in type narrowing. Previously if you used type guard functions, it resulted in no changes to the return type. Now the type would be narrowed, which might require updates to the application code that relied on the old behavior.

PR Close #48042
2023-04-03 19:35:35 -07:00
Matthieu Riegler
719f6a05fd refactor(core): remove unnecessary reflect-metadata import. (#49673)
The import is not needed for the tests to run.

PR Close #49673
2023-04-03 19:17:02 -07:00
Andrew Scott
d7d6514add feat(core): Add ability to configure NgZone in bootstrapApplication (#49557)
This commit adds a provider function that allows developers to configure
the `NgZone` instance for the application. In the future, this provider
will be used for applications to specifically opt-in to change detection
powered by ZoneJS rather than it being provided by default.

This API does _not_ specifically provide support for developers to define their own
`NgZone` implementation or opt in to `NoopNgZone` directly. Both of
these are possible today, but are effectively unsupported (applications
that use these are left to their own devices to run change detection at
the appropriate times). That said, developers can still use DI in
`bootstrapApplication` to provide an `NgZone` implementation instead,
it's just not specifically available in the
`provideZoneChangeDetection` function.

PR Close #49557
2023-03-31 11:56:10 -07:00
Andrew Scott
f982a3f965 feat(router): Opt-in for binding Router information to component inputs (#49633)
Adds ability for `RouterOutlet` to bind `Router` information to the routed
component's inputs. This commit also exposes some helpers for
implementers of custom outlets to do their own input binding if desired.

Resolves #18967

PR Close #49633
2023-03-30 16:10:54 -07:00
Andrew Scott
e9dd7f0028 refactor(core): Prevent reads and writes to signals at certain times (#49631)
* Prevent reads of signals during the notification process. This shouldn't
ever be triggered by user code but is more of a preventative for
internal misuse. Reading a signal during notification would/could create
glitches where the values being read are not updated to reflect the
values being updated by the notification.

* Prevent signal writes inside of computed's. These are meant to be
  derived values and should not have any side-effects like writing new
  values to other signals

* Prevent signal writes inside of effects by default. Writing to signal
  values during the execution of an effect can lead to the
  `ExpressionChangedAfterItHasBeenCheckedError` if writing to signals
  that represent global state which is read in a parent component. This is
  mostly just a problem for `OnPush`/`CheckAlways` components, but with
  signals being new and pure signal components not even available yet,
  it will be the majority for a long time.

PR Close #49631
2023-03-30 16:09:12 -07:00
Matthieu Riegler
39a648f31c refactor(core): Use (where applicable), ViewContainer.createComponent instead of relying on the ComponentFactoryResolver. (#49614)
`ComponentFactoryResolver` has been deprecated for public usage since its not necessary anymore. Lets reflect that in the unit tests.

PR Close #49614
2023-03-30 11:43:35 -07:00
Alan Agius
2703fd6260 refactor: remove deprecated EventManager method addGlobalEventListener (#49645)
This commit removed the deprecated `EventManager` method  `addGlobalEventListener`.

BREAKING CHANGE: Deprecated `EventManager` method `addGlobalEventListener` has been removed as it is not used by Ivy.

PR Close #49645
2023-03-30 09:47:54 -07:00
Pawel Kozlowski
267c5e8ca5 refactor(core): remove DeepReadonly type wrapper for signals (#49154)
We've been experimenting with the DeepReadonly type that would make
signal values deeply read-only and prevent accidental changes without
going to the owner of data. What we've found out during the experiments
is that additional safety net has more drawbacks than benefits: it just
introduces too much friction to be practical for daily usage.

PR Close #49154
2023-03-30 09:44:38 -07:00
Alex Rickabaugh
06e74a5583 refactor(core): run effects during change detection (#49641)
This commit updates the `effect` primitive and significantly changes the
timing of effect execution.

Previously, effects were scheduled via the microtask queue. This commit
changes effects to run throughout the change detection process instead.
Running effects this way avoids needing additional rounds of change
detection to resolve effects, with the tradeoff that they're harder to use
for model-to-model synchronization (which can be seen as a good thing).

PR Close #49641
2023-03-30 09:37:47 -07:00
Alex Rickabaugh
e254671efc refactor(core): consolidate LView state from injectors (#49641)
This commit consolidates the `RendererFactory` and `Sanitizer` properties
of `LView` onto a single object, the `LViewEnvironment`. These properties
are both set from DI when the root view is created, and not overridden when
child views are created (but inherited from the parent view).

This is a precursor commit to adding the `EffectManager` into the
`LViewEnvironment`.

PR Close #49641
2023-03-30 09:37:47 -07:00
Andrew Scott
3c7e637374 fix(router): Route matching should only happen once when navigating (#49163)
When navigating in the Router, the current approach does the redirects
and the creation of the `RouterStateSnapshot` in two separate steps
(applyRedirects and recognize). These two steps duplicate the route
matching logic, resulting in user code on routes being executing twice
(custom `UrlMatcher` and `canMatch` guards). This also duplicates the
complex matching logic in two places, which increases the bundle size
and maintenance burden.

This commit combines the `applyRedirects` and `recognize` steps into a
single matching algorithm.

fixes #26081

PR Close #49163
2023-03-29 14:40:41 -07:00
Andrew Scott
0432d952a1 Revert "fix(router): Route matching should only happen once when navigating (#49163)" (#49634)
This reverts commit 1600687fe5.

PR Close #49634
2023-03-29 11:37:29 -07:00