Commit graph

29946 commits

Author SHA1 Message Date
Kristiyan Kostadinov
8aef3f8dde docs: remove performance warning for directive composition (#55448)
Removes the warning about performance from the directive composition API docs since some recent benchmarks have snown that their effect is negligible.

PR Close #55448
2024-04-22 11:52:38 -07:00
Alan Agius
b0f1552ffe build: use installed deps from main repo (#55433)
This commit updates the zone.js types tests to use the deps installed in the main repo

PR Close #55433
2024-04-22 11:40:07 -07:00
Alan Agius
cb7fd67656 ci: disable updates to zone.js types test (#55433)
This breaks renovate
```
### ⚠ Artifact update problem

Renovate failed to update an artifact related to this branch. You probably do not want to merge this PR as-is.

♻ Renovate will retry this branch, including artifacts, only when one of the following happens:

 - any of the package files in this branch needs updating, or
 - the branch becomes conflicted, or
 - you click the rebase/retry checkbox if found above, or
 - you rename this PR's title to start with "rebase!" to trigger it manually

The artifact failure details are included below:

##### File name: packages/zone.js/test/typings/yarn.lock

```
error Package "zone.js" refers to a non-existing file '"/tmp/renovate/repos/github/angular/angular/dist/bin/packages/zone.js/npm_package"'.
```

PR Close #55433
2024-04-22 11:40:06 -07:00
Matthieu Riegler
bac5ba328e refactor(http): remove direct usage of HttpStatusCode (#55434)
PR #51670 removed the usage of `const enum`. As a consequence HttpStatusCode that were previously inlined now pull and retains the (fairly large) `HttpStatusCode` enum.

By intermediate constants, we prevent the framework from pulling this big enum by default.

PR Close #55434
2024-04-22 11:36:51 -07:00
Andrew Kushnir
ba0036c5c3 refactor(platform-server): remove inlined JSAction script when no events to replay (#55428)
JSAction script is inlined into the HTML by the build process to avoid extra blocking request. The script looks like this:

```
<script type="text/javascript" id="ng-event-dispatch-contract">...</script>
```

This commit updates the logic to remove JSAction if event replay feature is disabled or if there are no events to replay.

PR Close #55428
2024-04-22 11:36:21 -07:00
Alan Agius
b153459aaf build: update event dispatch contract to be outputted in IIFE (#55377)
This script is intended to be inlined in the HTML and thus IIFE should be preffered.

PR Close #55377
2024-04-22 11:35:48 -07:00
Matthieu Riegler
ebfba7751d docs: add anchors to packages on api page (#55338)
PR Close #55338
2024-04-22 11:28:41 -07:00
Angular Robot
a877a62884 build: update actions/cache digest to 0c45773 (#54950)
See associated pull request for more information.

PR Close #54950
2024-04-22 11:26:53 -07:00
Julien Saguet
6f88d80758 feat(http): allow caching requests with different origins between server and client (#55274)
Expose `HTTP_TRANSFER_CACHE_ORIGIN_MAP` injection token in public api. This is useful when different origins are used to access the same APIs between server and browser.

Fixes #53702

PR Close #55274
2024-04-22 11:26:09 -07:00
AleksanderBodurri
efe78d5565 fix(devtools): allow DevTools to fail gracefully for unsupported versions of Angular. (#55233)
Angular DevTools depends on many modern Angular features in order to function. As a result, at present the last officially supported version is v12. Angular DevTools may function for some Angular 9, 10 and 11 applications, but they are not officially supported.

This commit fixes an issue where DevTools would not inject a backend script into an Angular application if it detected it was below version 12. This backend script is important because it's used to inform the DevTools panel that the inspected application is in fact Angular, but that it is not on a supported version.

Angular 9, 10 and 11 applications that successfully have Angular DevTools initialize will now have a red highlight and tooltip on their version number, informing the user that they are using Angular DevTools on a version of Angular that is no longer supported.

Angular DevTools for applications that are below version 9 will continue to display the "Angular Devtools supports Angular versions 12 and above" message.

PR Close #55233
2024-04-22 11:25:20 -07:00
Pawel Kozlowski
832fafc6b5 refactor(core): warn developers about collection re-creation in @for loop (#55314)
This commit introduces a check plus an associated warning for situations where
the combination of the collection change and the tracking expression resulted
in the entire view structure managed by @for to be re-created.

The check uses the following conditions before raising a warning:
- the entire collection was re-created and there were no other operations (ex.: move);
- views in a collection are considered "expensive" to re-create;
- a developer is using tracking by identity.

The last condition tries to capture cases where changes to immutable data
collections can cause significent performance and / or corectness problems.

Note that this warning might be "overreacting" and report cases where
the collection re-creation is the intended behavior. Still, the assumption is that
most of the time it is undesired.

PR Close #55314
2024-04-22 11:24:11 -07:00
Andrew Scott
74333e6221 refactor(core): conditionally read data from apply args (#55465)
This commit fixes an error in a previous commit which attempted to read
`data` from the first item in the apply args array, even if it was not
defined.

PR Close #55465
2024-04-22 09:49:05 -07:00
Joey Perrott
b1dffa4abe refactor: migrate platform-* to prettier formatting (#55423)
Migrate formatting to prettier for platform-* from clang-format

PR Close #55423
2024-04-19 13:49:24 -07:00
Joey Perrott
488c711a57 refactor: migrate localize to prettier formatting (#55423)
Migrate formatting to prettier for localize from clang-format

PR Close #55423
2024-04-19 13:49:24 -07:00
Joey Perrott
a2aca69bd3 refactor: migrate forms to prettier formatting (#55423)
Migrate formatting to prettier for forms from clang-format

PR Close #55423
2024-04-19 13:49:24 -07:00
Angular Robot
a743d37f1c build: update scorecard action dependencies (#55419)
See associated pull request for more information.

PR Close #55419
2024-04-19 13:26:38 -07:00
Alan Agius
15f19820b0 build: update Domino to 8f228f8862540c6ccd14f76b5a1d9bb5458618af (#55424)
This contains the fix for https://github.com/angular/angular/issues/55416

PR Close #55424
2024-04-19 13:24:25 -07:00
Thomas Nguyen
a730f09ae9 feat(core): Add a public API to establish events to be replayed and an attribute to mark an element with an event handler. (#55356)
These will be consumed by the event-dispatch contract to replay events. The contract and the dispatcher inclusion will be in followups.

PR Close #55356
2024-04-19 13:12:21 -07:00
Angular Robot
b67e11a521 build: update cross-repo angular dependencies (#54891)
See associated pull request for more information.

PR Close #54891
2024-04-19 08:51:09 -07:00
Alan Agius
164dde45e6 refactor(migrations): remove v17 migrations (#55391)
This commit removes of migrations introduced in version 17, along with the relocation of a migration from 17.3 to version 18. This ensures that this is ran for users who may have updated from one minor to another without executing `ng update`

PR Close #55391
2024-04-19 06:31:28 -07:00
Matthieu Riegler
4d61501031 docs: fix filePath for manual api docs. (#55388)
Path should have a leading slash.

PR Close #55388
2024-04-19 06:30:34 -07:00
Matthieu Riegler
1bea1fe8a0 docs: improvements for API pages (#55388)
* add link for source files
* add deprecation message for methods
* add usage notes for methods

Fixes #55196
Fixes #52641

PR Close #55388
2024-04-19 06:30:34 -07:00
Kristiyan Kostadinov
7a16d7e969 fix(compiler-cli): don't type check the bodies of control flow nodes in basic mode (#55360)
Angular only checks the contents of template nodes in full type checking mode. After v17, the new control flow always had its body checked, even in basic mode, which started revealing compilation errors for apps that were using the schematic to automatically switch to the new syntax.

These changes mimic the old behavior by not checking the bodies of `if`, `switch` and `for` blocks in basic mode. Note that the expressions of the blocks are still going to be checked.

Fixes #52969.

PR Close #55360
2024-04-19 06:29:56 -07:00
Pawel Kozlowski
e67a730688 refactor(core): warn about duplicated keys when using built-in @for (#55243)
This commit a new check that warn users about duplicated keys detected given
a tracking expression and a collection iterated over with @for. Duplicated keys
should be avoided as those are more expensive to manage and can result in
incorrect UI display.

PR Close #55243
2024-04-19 06:28:58 -07:00
Andrew Scott
a0eebcd6d1 refactor(core): Add error tracking for infinite notifications (#55231)
This commit adds helpful stack information for the case when change
detection continues to be triggered in the event loop and would cause
the browser to freeze.

PR Close #55231
2024-04-19 06:25:46 -07:00
Andrew Scott
b47ac4d7c7 refactor(core): Account for Promise.resolve(() => updateState()) pattern in zoneless (#55231)
There is an existing pattern that zone-based applications use to avoid
`ExpressionChangedAfterItHasBeenCheckedError` which is also used in
`NgModel`: update the state in a microtask instead of doing it
synchronously. This defers the state update to another round of change
detection, and with ZoneJS, also still executes in the same event loop.
These types of changes across multiple rounds of change detection were
still executed before the browser paint.

This update allows the `NgModel` workaround to continue working in
Zoneless. This may not be permanent and is certainly still not
advisable. Render hooks (`afterNextRender`/`afterRender`) will execute between these
rounds of change detection when they are intended to be run after all
DOM updates completed.

PR Close #55231
2024-04-19 06:25:46 -07:00
Alan Agius
8eacb6e4b9 feat(http): exclude caching for authenticated HTTP requests (#55034)
This update modifies the transfer cache logic to prevent caching of HTTP requests that require authorization. To opt-out from this behaviour use the `includeRequestsWithAuthHeaders` option in `withHttpTransferCache`

BREAKING CHANGE: By default we now prevent caching of HTTP requests that require authorization . To opt-out from this behaviour use the `includeRequestsWithAuthHeaders` option in `withHttpTransferCache`.

Example:
```ts
withHttpTransferCache({
  includeRequestsWithAuthHeaders: true,
})
```

Closes: #54745

PR Close #55034
2024-04-19 06:25:22 -07:00
Joey Perrott
ca517d7f2c refactor: migrate language-service to prettier formatting (#55405)
Migrate formatting to prettier for language-service from clang-format

PR Close #55405
2024-04-18 14:18:38 -07:00
Joey Perrott
8f69c83b84 refactor: migrate compiler to prettier formatting (#55398)
Migrate formatting to prettier for compiler from clang-format

PR Close #55398
2024-04-18 14:18:08 -07:00
Joey Perrott
a5b5b7d5ef refactor: migrate core/primitives to prettier formatting (#55387)
Migrate formatting to prettier for core/primitives from clang-format

PR Close #55387
2024-04-17 15:55:32 -07:00
Andrew Scott
4a42961393 feat(router): withNavigationErrorHandler can convert errors to redirects (#55370)
This commit adds the ability to return `RedirectCommand` from the error
handler provided by `withNavigationErrorHandler`. This will prevent the
error from being surfaced in the `events` observable of the Router and
instead convert the error to a redirect. This allows developers to
have more control over how the Router handles navigation errors. There
are some cases when the application _does not_ want the URL to be reset
when an error occurs.

resolves #42915

PR Close #55370
2024-04-17 15:53:02 -07:00
Andrew Scott
18a43b56e5 refactor(core): Prevent running change detection twice with run coalescing and zoneless (#55352)
This commit ensures we correctly handle the exit from the zone.run in
the zoneless scheduler. Run coalescing would delay the `onMicrotaskEmpty` event
until after we have exited the change detection triggered by the
zoneless scheduler and mean that the subscription cannot determine if
`ApplicationRef.tick` should be skipped.

PR Close #55352
2024-04-17 15:50:59 -07:00
Gerald Monaco
5f06ca8f55 feat(core): add HOST_TAG_NAME token (#54751)
For ideal DOM usage, you would not unwrap an ElementRef outside of the browser. However, it's reasonable to want to find the tag name of the host node on the server, and so this introduces a HOST_TAG_NAME token that can be injected to read this value.

PR Close #54751
2024-04-17 15:50:31 -07:00
Angular Robot
e1eae847db build: update github/codeql-action action to v3.25.0 (#55358)
See associated pull request for more information.

PR Close #55358
2024-04-17 18:02:48 +02:00
Pawel Kozlowski
011cc06411 release: cut the v18.0.0-next.5 release 2024-04-17 17:55:10 +02:00
Pawel Kozlowski
9d2704c258 docs: release notes for the v17.3.5 release 2024-04-17 17:49:40 +02:00
Tom Wilkinson
a34267b72e refactor(core): Switch stopPropagation default to false (#55351)
Flip `stopPropagation` constructor parameter default to `false` for
`EventContract` and `EventContractMultiContainer`. Change type for
`EventContract` to `false` to indicate that no values besides `false`
should be passed. This enables removing all usages of `stopPropagation`
in `EventContract` and leaving only usages of `stopPropagation = true`
for `EventContractMultiContainer`.

PR Close #55351
2024-04-17 11:29:38 +02:00
Tom Wilkinson
0cec9e4f9a fix(core): Fix null dereference error addEvent (#55353)
When `cleanUp` is called `containerManager` is set to null. Currently
the `EventContract` API assumes that users know not to call further
methods on `EventContract`, but this lead to a bug in a downstream app,
b/333750059. So instead, this makes a defensive check to make sure it's
not null.

PR Close #55353
2024-04-17 11:29:00 +02:00
Alan Agius
9f5e90e03d build: make JSA contract binary accessible (#55361)
This commit integrates the JSA contract binary into the NPM package and ensures its accessibility by including it in the package exports. This adjustment is essential for enabling Angular CLI to effectively access and inject the script. Additionally, sourcemaps are removed from the minified bundle to prevent their inclusion in the HTML page.

PR Close #55361
2024-04-17 10:37:31 +02:00
Andrew Scott
ff686f3ca5 refactor(core): Permit detectChanges with zoneless ComponentFixture (#55325)
This commit loosens the restrictions on calling `ComponentFixture.detectChanges`
when using the zoneless scheduler. While we don't necessarily think it's
a good idea, the thought is that it's unnecessary mental overhead to
diverge behaviors in the API when zoneless is enabled versus when it is
not. Instead, these opinionated restrictions can be considered when we
look at new testing APIs.

PR Close #55325
2024-04-17 08:07:52 +02:00
Ben Hong
c778977445 docs: update v0 render to v17 (#55368)
PR Close #55368
2024-04-17 08:01:26 +02:00
Alan Agius
3b0de30b37 refactor(common): remove deprecated isPlatformWorkerApp and isPlatformWorkerUi API (#55302)
BREAKING CHANGE: The deprecated `isPlatformWorkerUi` and `isPlatformWorkerApp` have been removed without replacement, as they serve no purpose since the removal of the WebWorker platform.

PR Close #55302
2024-04-17 08:00:01 +02:00
Doug Parker
5f859727e2 release: bump Angular DevTools version to 1.0.13 (#55371)
PR Close #55371
2024-04-17 07:53:11 +02:00
Andrew Scott
de7447d15e fix(core): Angular should not ignore changes that happen outside the zone (#55102)
When Angular receives a clear indication that change detection should
run again, this should not be ignored, regardless of what Zone it
happened in. This change updates the default change detection scheduling
approach of Zone-based applications to ensure a change detection will
run when these events happen outside the Angular zone (which includes,
for example, updating a signal that's read in a template, setting an
input of a `ComponentRef`, attaching a view marked for check, calling
`ChangeDetectorRef.markForCheck`, etc.).

This does not apply to applications using `NoopNgZone` or those which
have a custom `NgZone` implementation without ZoneJS.

The impact of this change will most often be seen in existing unit tests. Tests
execute outside the Angular Zone and this can mean that state in the
test is not fully recognized by Angular. Now that Angular will ensure
change detection _does_ run, even when the state update originates from
outside the zone, tests may observe additional rounds of change
detection compared to the previous behavior. Often, this should be seen
as more correct and the test should be updated, but in cases where it is
too much effort to debug, the test can revert to the old behavior by adding
`provideZoneChangeDetection({schedulingMode: NgZoneSchedulingMode.NgZoneOnly})`
to the `TestBed` providers.

fixes #55238
fixes #53844
fixes #53841
fixes #52610
fixes #53566
fixes #52940
fixes #51970
fixes #51768
fixes #50702
fixes #50259
fixes #50266
fixes #50160
fixes #49940
fixes #49398
fixes #48890
fixes #48608
fixes #45105
fixes #42241
fixes #41553
fixes #37223
fixes #37062
fixes #35579
fixes #31695
fixes #24728
fixes #23697
fixes #19814
fixes #13957
fixes #11565
fixes #15770
fixes #15946
fixes #18254
fixes #19731
fixes #20112
fixes #22472
fixes #23697
fixes #24727
fixes #47236

BREAKING CHANGE:

Angular will ensure change detection runs, even when the state update originates from
outside the zone, tests may observe additional rounds of change
detection compared to the previous behavior.

This change will be more likely to impact existing unit tests.
This should usually be seen as more correct and the test should be updated,
but in cases where it is too much effort to debug, the test can revert to the old behavior by adding
`provideZoneChangeDetection({schedulingMode: NgZoneSchedulingMode.NgZoneOnly})`
to the `TestBed` providers.

Similarly, applications which may want to update state outside the zone
and _not_ trigger change detection can add
`provideZoneChangeDetection({schedulingMode: NgZoneSchedulingMode.NgZoneOnly})`
to the providers in `bootstrapApplication` or add
`schedulingMode: NgZoneSchedulingMode.NgZoneOnly` to the
`BootstrapOptions` of `bootstrapModule`.

PR Close #55102
2024-04-16 17:27:04 -07:00
Alex Rickabaugh
a5623dc14b Revert "refactor(core): warn about duplicated keys when using built-in @for (#55243)" (#55373)
This reverts commit 9f7b9ed87a. Reason: g3
users reported a bug in the logic that produces false warnings in some
cases.

PR Close #55373
2024-04-16 17:11:08 -07:00
Andrew Scott
e6425f7bc1 refactor(core): use patched timers in root zone for zoneless scheduler (#55367)
Rather than attempting to use the native timing functions, this commit
simplifies the logic significantly by using the global timer functions
as they are, either patched or unpatched. When Zone is defined, we run
the timers in the root zone. This has more predictable behavior and
timing than (a) using both patched and unpatched versions of timers in
different places (b) trying to get an unpatched timer and failing due to
environment specifics and patches that aren't ZoneJS.

We will try to update the coalescing behavior of ZoneJS in a future PR
to also just use the patched version of the timers instead of the
"fakeTopEvent" workaround with the native timers.

PR Close #55367
2024-04-16 16:31:19 -07:00
Andrew Scott
f09c5a7bc4 feat(core): Add zoneless change detection provider as experimental (#55329)
This commit adds the zoneless change detection provider function to the
public API surface as experimental.

PR Close #55329
2024-04-16 20:51:25 +02:00
Andrew Scott
785c3c1dd4 refactor(core): Calling ApplicationRef.tick should cancel scheduled change detections (#55290)
This commit ensures that manually calling ApplicationRef.tick will
result in any scheduled change detections being canceled. There is no
need for the scheduled one to run because it was manually done by the
`tick` already.

PR Close #55290
2024-04-16 20:50:35 +02:00
Andrew Scott
c3a5acb8cc refactor(core): change detection should not be scheduled during appRef.tick (#55290)
This commit ensures that change detection is not scheduled if the
scheduler is notified during an applicationRef.tick

PR Close #55290
2024-04-16 20:50:35 +02:00
arturovt
3bc63eaaf3 fix(service-worker): avoid running CDs on controllerchange (#54222)
This commit updates the implementation of `ngswAppInitializer` to configure
the `controllerchange` event listener outside of the Angular zone. This adjustment
is made to prevent unnecessary change detections, as the `controllerchange` event
is unrelated to view updates.

**NOTE**: This change may result in breaking unit tests that implicitly rely on a
specific number and sequence of change detections for their assertions to pass.

PR Close #54222
2024-04-16 17:29:59 +02:00