Commit graph

24 commits

Author SHA1 Message Date
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
Gerald Monaco
6145cc1c0a refactor(core): Ensure hydration cleanup runs in the Angular zone (#51321)
Hydration cleanup needs to run in the Angular zone so that change detection will run.

PR Close #51321
2023-08-15 16:02:06 -07:00
Matthieu Riegler
3b1c1b91a2 docs: Add Missing SSR integrity marker error doc page (#51340)
This commit adds an error doc page for error 507 : Missing SSR content integrity marker.

PR Close #51340
2023-08-14 14:39:25 -07:00
Matthieu Riegler
0a38dc3c26 refactor(core): throw an error when hydration marker is missing from DOM (#51170)
non-destructive hydration expects the DOM tree to have the same structure in both places.
With this commit, the app will throw an error if comments are stripped out by the http server (eg by some CDNs).

fixes #51160

PR Close #51170
2023-08-04 11:31:49 -04:00
Gerald Monaco
e53d4ecf4c feat(core): add afterRender and afterNextRender (#50607)
Add and expose the after*Render functions as developer preview

PR Close #50607
2023-08-01 13:02:27 -07:00
Alan Agius
28c68f709c fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425)
This commit updates the `ApplicationRef.isStable` API to account for
pending rendering task. This is needed as once a pending rendering task
is done, new macrotask and microtask could be created which previously caused these not
to be intercepted and thus ignored when doing SSR.

PR Close #50425
2023-05-30 12:58:22 -07:00
Matthieu Riegler
9afd90c59d refactor(core): Add a warning when ApplicationRef.isStable doesn't emit true (#50295)
Hydration requires a stable App to run some logic.
With this warning developers will be informed about potential issues encountered when running an unstable app.

Fixes #50285

PR Close #50295
2023-05-17 08:45:26 -07:00
Andrew Kushnir
946f9c2b95 refactor(core): drop next prefix from hydration guide link (#50214)
This commit updates the content of the console log to drop the `next.` prefix from hydration guide link.

PR Close #50214
2023-05-09 14:48:28 -07:00
Andrew Kushnir
f37cb477a8 refactor(core): log hydration setup warning in dev mode only (#49876)
This commit updates the code to log hydration setup warning in dev mode only. Previously, the warning was retained in the code even after optimization, thus making it into production bundles. The warning is meant to let developers know that hydration was enabled, but wasn't activated, so it's safe to tree-shake it away from production bundles.

PR Close #49876
2023-04-17 13:34:53 +00:00
Andrew Kushnir
54f18c832d refactor(core): rename internal DI token that indicates whether hydration is enabled (#49800)
This commit renames an internal token to better align it with the naming of the function (to highlight the fact that it's responsible for DOM part of the hydration).

PR Close #49800
2023-04-13 14:02:33 +00:00
Andrew Kushnir
7ee542d263 refactor(platform-server): include info about enabled features into ng-server-context (#49773)
This commit updates the logic that adds the "ng-server-context" attribute to the root elements to also include information about SSR feature enabled got an application.

PR Close #49773
2023-04-11 12:46:09 -07:00
Andrew Kushnir
83262dc0f9 refactor(core): do not enable hydration when server response was incorrect (#49750)
This commit updates the logic to avoid enabling hydration in case server response doesn't contain hydration-related info serialized. It can happen when `provideClientHydration()` call only happens on the client, but not on the server.

PR Close #49750
2023-04-10 09:03:20 -07:00
Andrew Kushnir
fe34de47bf refactor(core): add a warning when hydration annotation is missing in server response (#49743)
This commit updates the logic to detect a situation when hydration support was enabled only on the client. If that happens, Angular produces a warning in a console with a link to the error guide.

PR Close #49743
2023-04-07 09:41:55 -07:00
Andrew Kushnir
fe58f0a383 refactor(core): update the link in hydration stats message (#49728)
Currently, the link points to https://angular.io/guides/hydration and there are 2 issues with it: the `guides/hydration` should actually be `guide/hydration` and the guide is only available at https://next.angular.io, but not at https://angular.io. It will be available at https://angular.io once v16 final is released. For now, we can point to https://next.angular.io, so that developers testing hydration during the pre-release period can follow the link.

PR Close #49728
2023-04-06 11:00:59 -07:00
Andrew Kushnir
5bf2b7da6f refactor(core): skip hydration for components that use i18n (instead of throwing an error) (#49722)
Currently, non-destructive hydration for i18n blocks is not supported (but support is coming!).
This commit updates the serialization logic from throwing an error when it comes across an i18n
block to annotating a component with a skip hydration flag.

PR Close #49722
2023-04-06 10:59:26 -07:00
Andrew Kushnir
761e02d912 feat(platform-browser): add a public API function to enable non-destructive hydration (#49666)
This commit adds the `provideClientHydration` function to the public API. This function can be used to enable the non-destructive Angular hydration.

Important note: the non-destructive hydration feature is in Developer Preview mode, learn more about it at https://angular.io/guide/releases#developer-preview.

Before you can get started with hydration, you must have a server side rendered (SSR) application. Follow the [Angular Universal Guide](https://angular.io/guide/universal) to enable server side rendering first. Once you have SSR working with your application, you can enable hydration by visiting your main app component or module and importing `provideClientHydration` from `@angular/platform-browser`. You'll then add that provider to your app's bootstrapping providers list.

```typescript
import {
  bootstrapApplication,
  provideClientHydration,
} from '@angular/platform-browser';
// ...
bootstrapApplication(RootCmp, {
  providers: [provideClientHydration()]
});
```

Alternatively if you are using NgModules, you would add `provideClientHydration` to your root app module's provider list.

```typescript
import {provideClientHydration} from '@angular/platform-browser';
import {NgModule} from '@angular/core';

@NgModule({
  declarations: [RootCmp],
  exports: [RootCmp],
  bootstrap: [RootCmp],
  providers: [provideClientHydration()],
})
export class AppModule {}
```

You can confirm hydration is enabled by opening Developer Tools in your browser and viewing the console. You should see a message that includes hydration-related stats, such as the number of components and nodes hydrated.

Co-authored-by: jessicajaniuk <72768744+jessicajaniuk@users.noreply.github.com>
Co-authored-by: alan-agius4 <17563226+alan-agius4@users.noreply.github.com>

PR Close #49666
2023-04-03 22:13:47 -07:00
Andrew Kushnir
d786856c46 refactor(core): output hydration stats into a console in dev mode (#49617)
This commit adds a logic to output basic hydration stats into a console. This is also helpful to ensure that hydration is enabled and works.

PR Close #49617
2023-03-30 09:42:05 -07:00
Andrew Kushnir
478c5ac150 refactor(core): internal tracker of pending tasks during initial rendering (#49576)
This commit implements a simple tracker of the pending tasks during initial rendering. The class allows adding and removing tasks from the set. The class also exposes a promise that gets resolved once the last task is removed.

This tracker is needed to keep track of ongoing processes like Router navigation (and potentially HTTP requests) and acts as a signaling mechanism to SSR and hydration that the application is in the "stable" state and a serialization can be performed.

This class would also act as a future replacement for the `ApplicationRef.isStable` for zoneless applications.

PR Close #49576
2023-03-28 16:19:31 -07:00
Andrew Kushnir
3ef5d87408 refactor(core): post-hydration cleanup of unclaimed views (#49455)
This commit adds a logic to remove all views that were not cleaimed during the hydration. The process is started once the ApplicationRef becomes stable on the client (which matches the timing of serialization on the server).

PR Close #49455
2023-03-21 18:17:41 +01:00
Jessica Janiuk
1116c492fa refactor(core): Handle cases of lost empty text nodes during hydration (#49419)
During DOM serialization, empty text nodes are lost when the client parses the DOM. To solve this problem comment nodes are added where the empty nodes are located right before serialization. Those comments then get replaced during hydration with the proper empty text nodes.

PR Close #49419
2023-03-15 17:25:10 -07:00
Andrew Kushnir
22b895a5b1 refactor(core): add hydration logic for view containers (#49382)
This commit implements hydration support for view containers, which should make `*ngIf`, `*ngFor` and other structural directive work with hydration.

The logic also respects the `ngSkipHydration` flag and skips hydration in such cases.

PR Close #49382
2023-03-14 14:22:09 -07: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
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
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