Commit graph

3520 commits

Author SHA1 Message Date
Andrew Scott
4e098fa8a7 refactor(core): move Zone providers to a single provider function (#49373)
This commit moves the providers for `NgZone`-based change detection to a
single provider function. This function is currently called by default
in all places where `NgZone` was provided
(`bootstrapApplication`, `bootstrapModule`, and `TestBed`).

When we want to make Angular applications zoneless by default, we
can make a public provider method that has to be used in order to enable
the zone change detection features. When this method is not called,
Angular would use `NoopNgZone` by default and not initialize any
subscriptions to the `NgZone` stability events.

Side note: There are actually two places that `NgZone` is provided for `TestBed`
(providers in `compileTestModule` and `BrowserTestingModule`). This
likely doesn't need to be in both locations.

PR Close #49373
2023-03-14 09:20:53 -07:00
Andrew Scott
67c5272946 refactor(core): Extract microtask subscription and CD scheduling from ApplicationRef (#49373)
This refactor extracts the `NgZone` microtask subscription to a new
"ChangeDetectionScheduler". With this change, `ApplicationRef` not
longer injects `NgZone` directly. In the future, we can update the
providers that depend on `NgZone` to not use zones by default but
instead require a specific-opt in.

PR Close #49373
2023-03-14 09:20:53 -07:00
Andrew Scott
4d3bfcd570 refactor(core): Extract ApplicationRef error handling to a new internal token (#49373)
This extracts the zone-based error handling in `ApplicationRef` to a new
token. This works towards removing `NgZone` as a dependency in
`ApplicationRef`.

PR Close #49373
2023-03-14 09:20:52 -07:00
Andrew Scott
d423101a71 refactor(core): Move ApplicationRef.isStable implementation to a provider (#49373)
`ApplicationRef.isStable` is entirely powered by the state of `NgZone`.
The implementation should be part of `NgZone` code rather than built in
to `ApplicationRef`. In the future, `ApplicationRef.isStable` should
likely be removed in favor of the API living on the `NgZone`
class/interface instead.

PR Close #49373
2023-03-14 09:20:52 -07:00
Alan Agius
86fc4d3e98 refactor(platform-browser): remove internal TRANSITION_ID token (#48253)
This was a mirror copy of the `APP_ID` token.

PR Close #48253
2023-03-09 09:33:34 -08:00
Alan Agius
9165ff2517 fix(platform-browser): reuse server generated component styles (#48253)
Prior to this change component styles generated on the server where removed prior to the client side component being rendered and attached it's own styles. In some cases this caused flickering. To mitigate this `initialNavigation: enabledBlocking'` was introduced which allowed the remove of server styles to be defer to a latter stage when the application has finished initialization.

This commit changes the need for this, by not removing the server generated component styles and reuse them for client side rendering.

PR Close #48253
2023-03-09 09:33:34 -08:00
Alan Agius
0e5f9ba6f4 fix(core): generate consistent component IDs (#48253)
Prior to this change the component IDs where generated based on a counter. This is problematic as there is no guarantee that a component will get the same ID that was assigned on the server when generated on the client side.

This is paramount to be able to re-use the component styles generated on the server.

PR Close #48253
2023-03-09 09:33:34 -08:00
Alan Agius
852558366d refactor(core): split ɵɵdefineDirective and ɵɵdefineComponent (#49350)
Before this change `ɵɵdefineDirective` called `ɵɵdefineComponent` under the hood. This is problematic for the consistent component id generation as it could result in hash collisions for certain directives. Directives however do not require an id.

This changes moves common definition generation logic into a separate function that is re-used in `ɵɵdefineDirective` and `ɵɵdefineComponent`.

PR Close #49350
2023-03-08 13:07:53 -08:00
Matthieu Riegler
daaf0fd2f6 refactor(core): Remove isObservable() in favor isSubscribable(). (#49295)
The private util `isObservable` was actually just testing the same thing as`isSubscribable()`. As the implementation is closer to the function's name, let's only keep ``isSubscribable`.

PR Close #49295
2023-03-08 17:58:19 +00:00
Jessica Janiuk
5944f5d21e refactor(core): skip hydration annotation (#49345)
This adds the ngSkipHydration annotation, which allows users to
opt hydration boundaries out of hydration. This enables incremental
adoption of hydration by letting users skip hydration on components
that have implementation issues that conflict with hydration.

co-authored-by: AndrewKushnir <akushnir@google.com>

PR Close #49345
2023-03-08 17:56:43 +00:00
Andrew Kushnir
8e0a087674 refactor(core): hydration logic for <ng-container>s (#49303)
This commit incrementally builds on top of #49285 and adds the logic to hydrate <ng-container>s and their contents. This implementation supports simple <ng-container>s that don't have any Angular features (like *ngIf/*ngFor, etc) and are not content-projected.

The subsequent commits will extend the logic further to support more complex scenarios.

PR Close #49303
2023-03-07 23:56:45 +00:00
Alan Agius
fdf61974d1 feat(core): drop support for zone.js versions <=0.12.0 (#49331)
BREAKING CHANGE: `zone.js` versions `0.11.x` and `0.12.x` are not longer supported.

PR Close #49331
2023-03-07 19:12:22 +00:00
Jessica Janiuk
ed23974931 Revert "fix(platform-browser): KeyEventsPlugin should keep the same behavior (#49330)" (#49357)
This reverts commit 2312eb53ef.

PR Close #49357
2023-03-07 17:51:04 +00:00
Andrew Kushnir
e48930454a refactor(core): hydration logic for simple element and text nodes (#49285)
This commit incrementally builds on top of https://github.com/angular/angular/pull/49271 and adds the logic to hydrate elements and text nodes that don't have any Angular features (like *ngIf/*ngFor, etc) and are not content-projected.

The subsequent commits will extend the logic further to support more complex scenarios.

Co-authored-by: Jessica Janiuk <jessicajaniuk@google.com>
Co-authored-by: Andrew Kushnir <akushnir@google.com>

PR Close #49285
2023-03-06 19:43:41 +00:00
JiaLiPassion
2312eb53ef fix(platform-browser): KeyEventsPlugin should keep the same behavior (#49330)
Close #45698

KeyEventsPlugin now has different behavior with EventsPlugin, it will
always run inside ngZone with ngZone.runGuarded() no matter the
component is initialized inside or outside of NgZone, this PR
make sure KeyEventsPlugin bahave the same with other events.

PR Close #49330
2023-03-06 18:45:01 +00:00
Matthieu Riegler
6203a5e84e refactor(core): Remove ChangeDetectorStatus & isDefaultChangeDetectionStrategy (#49299)
Unused code in core and other packages. They were private exports.

PR Close #49299
2023-03-06 16:57:02 +00:00
Andrew Kushnir
1a1f260583 refactor(core): rename TNode.tViews to TNode.tView (#49313)
Previously (at the early days of Ivy) a TNode used to keep an array of TViews, but the logic was changed since that time, but the `tViews` field remained on TNode interface (+ corresponding typings).

This commit renames TNode.tViews to TNode.tView and cleans up typings.

PR Close #49313
2023-03-06 16:56:00 +00:00
Jessica Janiuk
4ae4090d3c refactor(platform-server): Implement hydration state transfer machinery (#49271)
**Important note**: this is a first commit in a series of commits that will be needed
to support non-destructive hydration. Stay tuned for further updates!

This commit lays the foundation on top of which more hydration logic will be
added in follow up PRs. This PR includes:

* Initial serialization of hydration data
* Data transfer of hydration annotations from server side to client
* Accessing hydration info and populating internal data structures
* Initial APIs (currently private) that enable hydration (in a tree-shakable manner)
* Cleanup of annotations post hydration
* Initial test infrastructure and basic test cases

This commit does **not** expose any public APIs. They'll be exposed later, when
more hydration logic is implemented to a state when it can cover most common
use-cases.

Co-authored-by: Jessica Janiuk <jessicajaniuk@google.com>
Co-authored-by: Andrew Kushnir <akushnir@google.com>

PR Close #49271
2023-03-06 16:53:37 +00:00
Andrew Scott
e1355e7d16 refactor(migrations): Move ChangeTracker to common utils (#49308)
The `ChangeTracker` is generally useful and could be used by a lot of
migrations instead of having to rewrite similar boilerplate.

PR Close #49308
2023-03-03 22:03:37 +00:00
Matthieu Riegler
594e68cc4b refactor(core): Remove ɵivyEnabled (#49296)
The unit tests have been updated in #44120, this export is unused now.

PR Close #49296
2023-03-03 19:41:09 +00:00
Kristiyan Kostadinov
10c8eae6d4 refactor(migrations): expose current file in import remapper (#49288)
Passes the path of the current file to the import remapper. Useful if we want to generate absolute paths.

PR Close #49288
2023-03-02 21:48:34 +00:00
Dylan Hunn
675fe2fabc refactor(core): Clean up getNgZone implementation. (#49241)
The current implementation is a bit confusing to read. Get rid of some of the operator soup.

PR Close #49241
2023-03-02 21:48:05 +00:00
Matthieu Riegler
e57d5db045 refactor(core): remove unused r2 debug code (#49292)
`_createNgProbeR2` isn't called anymore, `ɵgetDebugNodeR2` isn't needed anymore. We can now remove it from the export in Core.

PR Close #49292
2023-03-02 21:47:25 +00:00
Matthieu Riegler
3f650bd200 refactor(core): Remove isListLikeIterable from private export. (#49297)
PR #48433 removed the last external usage of `isListLikeIterable`. We can now remove it from the private exports.

PR Close #49297
2023-03-02 20:53:01 +00:00
Matthieu Riegler
cc34d5b6ef refactor(core): Application ref/init code cleaning (#49206)
* With tsc improvements some types can be refined.
* Removing unnecessary non-null assertions.
* Using std native methods instand of custom functions
* Using @ts-expect-error instead of `any` type assertion to keep code navigation.

PR Close #49206
2023-03-02 20:01:39 +00:00
Matthieu Riegler
8beb8526be refactor: remove duplicate key from component metadata (#49065)
`directiveMetadata()` already assigns the `standalone` property to the `R3ComponentMetadataFacade` there is no need to do it twice.

PR Close #49065
2023-03-01 22:36:50 +00:00
Matthieu Riegler
6d9e979be1 refactor(router): use native functions instead of custom utils (#49209)
* flatten() => flat()
* forEach() => Object.entries/values/keys().forEach()
* and() => every()

PR Close #49209
2023-03-01 22:35:07 +00:00
Alan Agius
b5278cc115 feat(platform-server): renderApplication now accepts a bootstrapping method (#49248)
The `renderApplication` now also accepts a bootstrapping function call with return `Promise<ApplicationRef>`as the first parameter.

Example:
```ts
 const bootstrap = () => bootstrapApplication(RootComponent, appConfig);

 const output: string = await renderApplication(bootstrap);
```

PR Close #49248
2023-03-01 22:31:33 +00:00
Alan Agius
4e9531f777 feat(core): add mergeApplicationConfig method (#49253)
This commits add a utility method to merge multiple `ApplicationConfiguration` into one from left to right.  This is useful for server rendering were an application might have several configurations.

Usage Example:
```ts
const config = mergeApplicationConfig(appConfig, appServerConfig);
```

PR Close #49253
2023-03-01 11:20:31 -08:00
Alan Agius
3aa85a8087 refactor(platform-browser): move ApplicationConfig to core (#49253)
This is needed to provide the merge configuration method which will reside in core.

DEPRECATED: `ApplicationConfig` has moved, please import `ApplicationConfig` from `@angular/core` instead.

PR Close #49253
2023-03-01 11:20:31 -08:00
Andrew Kushnir
030060e3dc refactor(core): use lower-level API to annotate TransferState class (#49272)
This commit updates the `TransferState` class and replaces the `@Injectable` decorator with a lower-level function call. This is a common practice for token defined in `core`, for example:

* https://github.com/angular/angular/blob/main/packages/core/src/change_detection/differs/iterable_differs.ts#L193-L196
* https://github.com/angular/angular/blob/main/packages/core/src/di/injector.ts#L121-L126

This is needed to avoid cirular references when using `TransferState` in other locations in `core`, for
example: https://github.com/angular/angular/pull/49271. Circular dependencies are coming from the fact t
hat the `@Injectable` from the `packages/core/src/di/injectable.ts` file refers to a number of extra symbols.

PR Close #49272
2023-03-01 11:19:10 -08:00
Andrew Kushnir
41bed349a8 refactor(core): move APP_BOOTSTRAP_LISTENER to avoid circular deps (#49273)
This commit moves the `APP_BOOTSTRAP_LISTENER` token into the `application_ref.ts` to avoid a risk of circular dependencies. The main problem is that the token refers to the `ComponentRef`, which in turn refers to more symbols, thus making the `application_tokens.ts` file susceptible to circular dependencies. Such a dependency was identified in https://github.com/angular/angular/pull/49271.

PR Close #49273
2023-03-01 11:18:27 -08:00
Kristiyan Kostadinov
2fbaee3cbe fix(migrations): add protractor support if protractor imports are detected (#49274)
The new `bootstrapApplication` API doesn't include Protractor support anymore which may cause existing e2e tests to break after the migration. These changes add some logic that will provide Protractor support if any imports to `protractor` or `protractor/*` are detected.

PR Close #49274
2023-03-01 11:13:56 -08:00
Jessica Janiuk
a08a8ff108 fix(platform-server): bundle @angular/domino in via esbuild (#49229)
This removes one line that should effectively bundle the
angular fork of domino in via esbuild.

PR Close #49229
2023-02-28 13:34:50 -08:00
Alan Agius
e9edea363c fix(core): update zone.js peerDependencies ranges (#49244)
This ensures that the latest version of zone.js is supported.

PR Close #49244
2023-02-28 11:55:53 -08:00
Pawel Kozlowski
0f5c8003cc feat(core): introduce concept of DestroyRef (#49158)
DestroyRef represents a concept of lifecycle scope where destroy
callbacks can be registered. Such callbacks are automatically
executed when a given scope ends it lifecycle.

In practice the most common  lifecycle scopes would be represented by:
 - a component or en embedded view;
 - instance of `EnvironnementInjector`.

PR Close #49158
2023-02-28 11:52:09 -08:00
Alan Agius
f594725951 refactor(core): remove Node.js v14 support (#49255)
BREAKING CHANGE: Node.js v14 support has been removed

Node.js v14 is planned to be End-of-Life on 2023-04-30. Angular will stop supporting Node.js v14 in Angular v16. Angular v16 will continue to officially support Node.js versions v16 and v18.

PR Close #49255
2023-02-28 11:00:25 -08:00
Matthieu Riegler
7b9a082c92 refactor(core): Drop Symbol.iterator shim (#49207)
We are targeting evergreen browsers, we can drop the shim.

PR Close #49207
2023-02-28 10:05:41 -08:00
Kristiyan Kostadinov
87affadb87 fix(migrations): avoid migrating the same class multiple times in standalone migration (#49245)
If a class is declared in multiple modules, the standalone migration may end up generating invalid code. While declaring a class in multiple modules is an error, it can happen with modules in tests. These changes avoid the issue by using a `Set` to track the classes being migrated.

PR Close #49245
2023-02-28 10:04:54 -08:00
Kristiyan Kostadinov
99d874fe3b feat(core): add support for TypeScript 5.0 (#49126)
Updates the project to support TypeScript 5.0 and to resolve any errors that came up as a result of the update.

PR Close #49126
2023-02-28 08:24:47 -08:00
Andrew Scott
31f210bf2c fix(router): Router.createUrlTree should work with any ActivatedRoute (#48508)
This change makes the `createUrlTreeFromSnapshot` added in #45877 the
default and only behavior in the Router. This now addreses #42191, #38276, #22763,
and #48472 without needing to create custom handling to
call `createUrlTreeFromSnapshot` (since it's now called by `Router.createUrlTree`).

BREAKING CHANGE: Tests which mock `ActivatedRoute` instances may need to be adjusted
because Router.createUrlTree now does the right thing in more
scenarios. This means that tests with invalid/incomplete ActivatedRoute mocks
may behave differently than before. Additionally, tests may now navigate
to a real URL where before they would navigate to the root. Ensure that
tests provide expected routes to match.
There is rarely production impact, but it has been found that relative
navigations when using an `ActivatedRoute` that does not appear in the
current router state were effectively ignored in the past. By creating
the correct URLs, this sometimes resulted in different navigation
behavior in the application. Most often, this happens when attempting to
create a navigation that only updates query params using an empty
command array, for example `router.navigate([], {relativeTo: route,
queryParams: newQueryParams})`. In this case, the `relativeTo` property
should be removed.

PR Close #48508
2023-02-28 08:21:20 -08:00
Andrew Kushnir
a5dc9960dc refactor(core): move TransferState implementation to core (#49222)
This commit moves the `TransferState` class implementation to `@angular/core`. This class will be needed in core in followup changes and `core` can not depend on `platform-browser` package.

The `core` package does **not** export those symbols into public API surface.
The `platform-browser` package re-exports the symbols under same names for backwards-compatibility.

PR Close #49222
2023-02-27 13:08:40 -08:00
Iván Navarro
7e35a917c5 fix(router): add error message when using loadComponent with a NgModule (#49164)
Add a more specific error message when defining a lazy-loaded route using
`loadComponent` and passing it a NgModule instead of a standalone component,
when the user should actually be using `loadChildren`.

PR Close #49164
2023-02-27 10:09:55 -08:00
Andrew Kushnir
b4703a7686 refactor(core): add previous sibling node reference to TNode (#49223)
This commit updates the `TNode` to include a reference to the previous sibling node. Currently, TNode has references to the next sibling and parent nodes, but in followup changes we'd need to have access to previous TNodes (to determine position of the current node).

PR Close #49223
2023-02-27 10:00:25 -08:00
Andrew Kushnir
02f4599669 refactor(core): avoid creating DOM nodes before creating a TNode (#49172)
This commit updates the `elementStart` instruction to avoid creating DOM nodes before creating a corresponding TNode. This refactoring is needed to make sure this internal logic is consistent across all instructions.

PR Close #49172
2023-02-24 08:29:05 -08:00
Kristiyan Kostadinov
7dd19570e8 fix(migrations): delete barrel exports in standalone migration (#49176)
Adds some logic to automatically delete `export * from './foo'` style imports. Previously they weren't being picked up, because finding all the references using the language service doesn't include barrel exports.

PR Close #49176
2023-02-24 08:23:01 -08:00
Kristiyan Kostadinov
79cdfeb392 feat(compiler): drop support for TypeScript 4.8 (#49155)
Drops support for TypeScript 4.8 from the compiler and removes all of the compatibility code we had for it.

BREAKING CHANGE:
* TypeScript 4.8 is no longer supported.

PR Close #49155
2023-02-23 10:39:43 -08:00
cexbrayat
660fbf5d27 fix(migrations): migrate HttpClientModule to provideHttpClient() (#48949)
The `standalone-bootstrap` migration now migrates `HttpClientModule` imports to `provideHttpClient(withInterceptorsFromDi())` instead of `importProvidersFrom(HttpClientModule)`.

The `withInterceptorsFromDi()` feature is added to make sure class-based interceptors still works if there are any in the application.

Fixes #48948

PR Close #48949
2023-02-22 11:30:00 -08:00
Mladen Jakovljević
71d5cdae19 docs: fix examples in signals README.md (#49156)
PR Close #49156
2023-02-22 11:28:30 -08:00
Alex Rickabaugh
bc5ddabdcb feat(core): add Angular Signals to the public API (#49150)
This commit exposes `signal`, `computed`, `effect` and various helpers from
the `@angular/core` entrypoint.

These APIs are marked as `@developerPreview` and are still prototypes in
active development. Their final shapes will be subject to our internal
design reviews as well as one or more community RFCs. We're exporting them
now to allow for experimentation using 16.0.0 next and RC releases.

PR Close #49150
2023-02-22 11:27:21 -08:00