Commit graph

474 commits

Author SHA1 Message Date
Kristiyan Kostadinov
1cfbfc66d3 fix(platform-server): remove peer dependency on animations (#58997)
The `@angular/platform-server` package had a peer dependency on `@angular/animations` which wasn't being used anywhere.

PR Close #58997
2024-12-02 11:33:04 +01:00
Jessica Janiuk
30891d8dec refactor(core): Consolidates shouldTrigger* methods down to one (#58833)
This cleans up the triggering code base and consolidates it down to one
function that outlines the logic. This also resolves the `hydrate when`
behavior issue.

fixes: #58709

PR Close #58833
2024-11-27 17:00:06 +01:00
Andrew Kushnir
7f6f5f95ea refactor(core): use ApplicationRef.whenStable instead of a custom util function (#58834)
This commit removes a custom `whenStable` util in favor of standard `ApplicationRef.whenStable` API.

There is also an important different between the custom `whenStable` function and `ApplicationRef.whenStable` implementation: the `whenStable` was caching the "stable" promise on per-ApplicationRef basis, which resulted in unexpected behavior with zoneless, when some code ended up getting a stale resolved promise, when an application was not stable yet, this causing order of operations issues. This commit also has an extra test that covers that case.

PR Close #58834
2024-11-25 15:25:10 +00:00
Jessica Janiuk
bd08d1ddac fix(core): Prevents race condition of cleanup for incremental hydration (#58722)
When hydrating a tree of blocks, this prevents cleanup from firing more than once per tree. It also ensures the cleanup happens after hydration has finished.

fixes: #58690

PR Close #58722
2024-11-21 21:39:37 +00:00
Jessica Janiuk
292d819e92 fix(core): fixes issues with control flow and incremental hydration (#58644)
If a defer block is nested inside control flow while also being nested
underneath a defer block all using incremental hydration, timing issues
prevented the child nodes from being properly hydrated. This ensures
hydration happens on next render.

PR Close #58644
2024-11-14 14:59:53 +00:00
Kristiyan Kostadinov
c421ffdbfb fix(compiler): control flow nodes with root at the end projected incorrectly (#58607)
Fixes an edge case where a control flow node that has non-projectable nodes followed by an element node at the end would cause the entire control flow node to be project. For example if we have a projection target of `Main: <ng-content/> Slot: <ng-content select="[foo]"/>`, inserting a node of `@if (true) {Hello <span foo>world</span>}` would project the entire `Hello world` into the `[foo]` slot.

In the process of working on the issue, I also found that `@let` declarations at the root of the control flow node would prevent content projection as well.

PR Close #58607
2024-11-12 18:05:00 +00:00
Jessica Janiuk
e3343620b5 test(core): add incremental hydration tests (#58601)
This adds some additional tests for incremental hydration around registry and contract cleanup.

PR Close #58601
2024-11-12 14:49:06 +00:00
Alan Agius
1035b47d0b test(platform-server): fix issue with ngServerMode when focusing fit tests (#58538)
This commit addresses a problem with tests that use the `fit` function to focus on individual test cases. While these tests run successfully in the full suite, they fail when focused individually using `fit`.

The issue lies in the behavior of `withEventReply` and other hydration-related functions (i.e., `provideX`, `withX`). These functions return platform-specific providers based on the `ngServerMode` setting, causing inconsistencies between server and browser environments. As a result, provider instances cannot be reused across server and browser applications.

**Example of problematic code:**
```ts
const hydrationFeatures = [withEventReply()];
const html = await ssr(SimpleComponent, { hydrationFeatures });
// Expected behavior ...

const appRef = await prepareEnvironmentAndHydrate(doc, html, SimpleComponent, {
  hydrationFeatures,
});
// Expected behavior ...
```

**Solution:**
To address this, we define `hydrationFeatures` as a function instead of a static array. This ensures that a new instance of `withEventReply` is created separately for each environment, eliminating platform-specific mismatches between server and browser contexts:

```typescript
const hydrationFeatures = () => [withEventReply()];  // Define as a function
const html = await ssr(SimpleComponent, { hydrationFeatures: hydrationFeatures() });
// Expected behavior ...

const appRef = await prepareEnvironmentAndHydrate(doc, html, SimpleComponent, {
  hydrationFeatures: hydrationFeatures(),
});
// Expected behavior ...
```

PR Close #58538
2024-11-07 14:29:59 +00:00
Alan Agius
378284fa08 refactor(core): introduce ngServerMode as global (#58386)
This commit adds the `ngServerMode` as global, which allows for the tree-shaking of server-only code from the bundles. When this flag is unset at runtime, server-specific code will be excluded by Closure, optimizing bundle size.

**Internal Angular Flag:** This is an internal Angular flag (not a public API), avoid relying on it in application code.

PR Close #58386
2024-10-30 10:13:28 -07:00
Jessica Janiuk
acd4f80737 fix(core): Prevents trying to trigger incremental hydration on CSR (#58366)
hydrate triggers were firing in CSR cases and attempting to find parent defer blocks. This prevents that from happening. In these cases, the defer block id will be empty.

fixes: #58359

PR Close #58366
2024-10-29 05:07:37 -07:00
Jessica Janiuk
7a5d1292d0 refactor(core): prevent annotating in hydrate never blocks (#58328)
This fixes an issue with hydrate never where jsaction annotations would still hydrate even when they should not.'

PR Close #58328
2024-10-24 16:20:52 -07:00
Matthieu Riegler
5d9cc8f408 refactor(core): remove the standalone feature (#58288)
By removing the standalone feature, we reduce the amount of code generated for components but at the cost of including the `StandaloneService` in the main bundle even if no standalone components are included in it.

PR Close #58288
2024-10-24 16:19:02 -07:00
Jessica Janiuk
08e6ccb758 refactor(core): incremental hydration cleanup (#58290)
This cleans up a few bits of implementation in the incremental hydration code.

PR Close #58290
2024-10-22 09:43:43 -07:00
Jessica Janiuk
69fc5ae922 feat(core): Add incremental hydration public api (#58249)
This exposes the public api to utilize incremental hydration.

PR Close #58249
2024-10-22 09:37:31 -07:00
Jessica Janiuk
95449302e9 refactor(core): add incremental hydration infrastructure (#58193)
This adds the bulk of the infrastructure to support
incremental hydration.

PR Close #58193
2024-10-21 12:05:06 -07:00
Jessica Janiuk
e603e5616d test(core): fix flaky hydration test (#58252)
This clears the DebugConsole between each test, which should address cross-test console noise.

PR Close #58252
2024-10-17 15:58:30 -07:00
Jessica Janiuk
d8b5f4e0c2 refactor(core): restructure hydration test files (#58196)
This re-organizes the hydration tests to make it easier to add new tests. Incremental hydration can have tests in a separate file after this groundwork is landed.

PR Close #58196
2024-10-14 14:26:26 -07:00
Matthieu Riegler
09df589e31 refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160)
All components, directives and pipes will now use standalone as default.
Non-standalone decorators have now `standalone: false`.

PR Close #58160
2024-10-14 14:58:57 +00:00
Krzysztof Platis
9e82559de4 fix(platform-server): destroy PlatformRef when error happens during the bootstrap() phase (#58112)
The `bootstrap()` phase might fail e.g. due to an rejected promise in some `APP_INIIALIZER`.
If `PlatformRef` is not destroyed, then the main app's injector is not destroyed and therefore `ngOnDestroy` hooks of singleton services is not called on the end (failure) of SSR.

This could lead to possible memory leaks in custom SSR apps, if their singleton services' `ngOnDestroy` hooks contained an important teardown logic (e.g. unsubscribing from RxJS observable).

Note: I needed to fix by the way another thing too: now we destroy `moduleRef` when `platformInjector` is destroyed - by setting a `PLATFORM_DESTROY_LISTENER`

fixes #58111

PR Close #58112
2024-10-09 12:12:34 +00:00
Matthieu Riegler
84b6896956 refactor(platform-server): Add an ssr benchmark setup. (#57647)
In order to investigate the performances of SSR, this commit introduces a benchmark suite which will measure several step of the rendering.

PR Close #57647
2024-10-04 10:45:22 -07:00
Andrew Kushnir
222544491b refactor(core): avoid hydration warnings when RenderMode.Client is set (#58004)
With the newly-added `RenderMode` config for routes, some of the routes may have the `RenderMode.Client` mode enabled, while also having `provideClientHydration()` function in provider list at bootstrap. As a result, there was a false-positive warning in a console, notifying developers about hydration misconfiguration.

This commit adds extra logic to handle this situation and avoid such warnings.

Note: there is a change required on the CLI side to add an extra marker, which would activate the logic added in this commit.

PR Close #58004
2024-10-02 11:45:28 +00:00
Matthieu Riegler
f2bea3b73d refactor(platform-server): remove HttpClientModule import (#58016)
This import is not necessary anymore.

fixes #57983

PR Close #58016
2024-09-30 13:41:48 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Andrew Kushnir
b124e50ea3 refactor(core): avoid producing zone-related warnings during hydration when in zoneless mode (#57911)
This commit updates hydration code to avoid logging "unsupported configuration" warnings when in zoneless mode.

PR Close #57911
2024-09-24 12:52:40 +02:00
Matthieu Riegler
4231e8f28f fix(core): Handle @let declaration with array when preparingForHydration (#57816)
Before this commit, `@let` decleration with an array where  mistaken for a component in the lView and throwing an unexpected error.

This commit fixes this.

PR Close #57816
2024-09-17 16:29:39 +02:00
Alan Agius
d5cc9d5d71 feat(bazel): remove unused ESM2022 from APF (#57559)
We have removed the `esm2022` directory from the generated package, as it was unused and contributed 7.7 MB to `@angular/core`. The `ng_package` rule still passes `esm2022` to the packager to perform `analyzeFileAndEnsureNoCrossImports`.

A moment of reflection:
You've always been there, full of potential, yet never called upon. Now, we bid you farewell.

PR Close #57559
2024-08-28 08:45:38 -07:00
Thomas Nguyen
7a99815146 fix(core): Do not bubble capture events. (#57476)
These should only fire if the target is the same as the targetElement. Also, delete an out of date test since capture/non-capture tests are separately covered.

PR Close #57476
2024-08-23 14:46:54 -07:00
Andrew Kushnir
d4449fce21 fix(core): handle hydration of components that project content conditionally (#57383)
This commit fixes an issue when hydration serialization tries to calculate DOM path to a content projection node (`<ng-content>`), but such nodes do not have DOM representation.

Resolves #56750.

PR Close #57383
2024-08-15 11:22:04 -04:00
Andrew Kushnir
84827d5958 fix(core): skip hydration for i18n nodes that were not projected (#57356)
This commit fixes an issue that happens when an i18n block is defined as a projectable content, but a parent component doesn't project it. With an extra check added in this commit, the code will be taking a regular "creation" pass instead of attempting hydration.

Resolves #57301.

PR Close #57356
2024-08-13 09:42:41 -07:00
Andrew Kushnir
45212c7fd9 fix(core): take skip hydration flag into account while hydrating i18n blocks (#57299)
This commit updates serialization and hydration i18n logic to take into account situations when i18n blocks are located within "skip hydration" blocks.

Resolves #57105.

PR Close #57299
2024-08-09 08:07:48 -07:00
Andrew Kushnir
26ddbdb89c fix(core): complete post-hydration cleanup in components that use ViewContainerRef (#57300)
Previously, if a component injects a `ViewContainerRef`, the post-hydration cleanup process doesn't visit inner views to cleanup dehydrated views in nested LContainers. This commit updates the logic to recognize this situation and enter host LView to complete cleanup.

Resolves #56989.

PR Close #57300
2024-08-09 08:07:12 -07:00
Kristiyan Kostadinov
513a4fe05e refactor(core): replace usages of removeChild (#57203)
These changes replace most usages of `removeChild` with `remove`. The latter has the advantage of not having to look up the `parentNode` and ensure that the child being removed actually belongs to the specific parent.

The refactor should be fairly safe since all the browsers we cover support `remove`. [Something similar was done in Components](https://github.com/angular/components/pull/23592) some time ago and there haven't been any bug reports as a result.

PR Close #57203
2024-08-07 16:46:09 +00:00
Kristiyan Kostadinov
a752178f28 fix(core): hydration error in some let declaration setups (#57173)
Fixes that we were throwing an assertion error during hydration if a `@let` declaration is used before and immediately inside of a container.

Fixes #57160.

PR Close #57173
2024-07-30 16:43:46 +00:00
Tom Wilkinson
d011c9f7ba refactor(core): Refactor EarlyEventContract to prepare for using it as a container. (#56900)
This is the first step towards combining `EarlyEventContract` and `EventContract`. It contains a few refactors, such as making names more consistent.

The goal of this refactor is to remove the `EarlyEventContract` class altogether, as well as `EventContract`.

To install the early event contract with the default events in early script tag, users will call:

`bootstrapGlobalEarlyEventContract()`

And for boostraping:

`registerGlobalDispatcher(dispatcher)`

PR Close #56900
2024-07-10 13:53:03 -07:00
Matthieu Riegler
31b235b94b refactor(platform-server): Add private profiler. (#56274)
The commit adds a private profiler to investigate SSR performance.

PR Close #56274
2024-07-09 12:47:45 +02:00
Kristiyan Kostadinov
0a48d584f2 feat(core): add support for let syntax (#56715)
Enables the new `@let` syntax by default.

`@let` declarations are defined as:
1. The `@let` keyword.
2. Followed by one or more whitespaces.
3. Followed by a valid JavaScript name and zero or more whitespaces.
4. Followed by the `=` symbol and zero or more whitespaces.
5. Followed by an Angular expression which can be multi-line.
6. Terminated by the `;` symbol.

Example usage:
```
@let user = user$ | async;
@let greeting = user ? 'Hello, ' + user.name : 'Loading';
<h1>{{greeting}}</h1>
```

Fixes #15280.

PR Close #56715
2024-06-26 12:37:02 -07:00
Kristiyan Kostadinov
7dfe302f47 refactor(core): support let declarations during hydration (#56527)
Updates the hydration logic to account for the fact that let declarations don't create a DOM node.

PR Close #56527
2024-06-26 08:48:31 -07:00
Gerald Monaco
29ca6d10cc fix(core): improve support for i18n hydration of projected content (#56192)
When collecting nodes from the DOM for hydration, we need to treat nodes with paths (e.g. content projection) as the new root for all subsequent elements, not just the next one.

Additionally, when using content projection it's possible for translated content to become disconnected, e.g. when it doesn't match a selector and there isn't a default. We need to handle such cases by manipulating the disconnected node data associated with hydration as usual.

PR Close #56192
2024-06-20 14:59:57 -07:00
Andrew Kushnir
bf6df6f186 fix(core): do not activate event replay when no events are registered (#56509)
This commit adds extra checks to handle a situation when an application has no events configured, but the Event Replay feature was enabled. This situation can happen when some routes in an application are mostly static, when other routes are more interactive.

Resolves #56423.

PR Close #56509
2024-06-20 08:53:18 -07:00
Joey Perrott
0bd55a684f refactor(docs-infra): complete removal of aio directory (#56496)
Finish removal of aio directory as it is no longer used or relied upon.

PR Close #56496
2024-06-18 12:26:00 -07:00
Thomas Nguyen
6e89ef1ebf refactor(core): Refactor parts of event_replay into a shared library that will be used with global event delegation. (#56172)
This also moves the code that stashes the jsaction more closely to the code that actually sets the event listener.

PR Close #56172
2024-06-05 16:35:23 +00:00
Alan Agius
01172b84d9 build: update Node.js to match Angular CLI engines (#56187)
The current supported Node.js engines by the Angular CLI are `^18.19.1 || ^20.11.1 || >=22.0.0`

PR Close #56187
2024-06-03 18:00:46 +00:00
Andrew Kushnir
31f3975e4b fix(core): handle missing withI18nSupport() call for components that use i18n blocks (#56175)
This commit updates hydration serialization logic to handle a case when the `withI18nSupport()` call is not present for an application that has a component that uses i18n blocks. Note: the issue is only reproducible for components that also inject `ViewContainerRef`, since it triggers a special serialization code path.

Resolves #56074.

PR Close #56175
2024-05-30 18:36:58 +00:00
Thomas Nguyen
1223122080 refactor(core): Use event_dispatcher in event_replay code. (#56036)
This makes events bubble! This change also contains changes to
dispatcher and event_dispatcher to make replay synchronous,
so that we avoid odd timing issues. This can be split out though.

Lastly, we have one cleanup change to move the mapping from
event type to functions on the element itself.

PR Close #56036
2024-05-29 12:59:23 +02:00
Andrew Kushnir
ae83646704 fix(core): handle elements with local refs in event replay serialization logic (#56076)
Previously, the event replay serialization logic was located before we verify that a `TNode` exists. `TNode`s may not exist in `tView.data` array in several cases, including cases when there is a local ref used on an element: in this case an extra slot in `LView` contains a reference to the same element and `TNode` is not needed. This commit moves the event replay serialization logic a bit lower, after we check for TNode presence.

Resolves #56073.

PR Close #56076
2024-05-27 13:50:09 +02:00
Thomas Nguyen
690b0fb9af refactor(core): Create event types that are able to be serialized, captured, or are mouse events. (#55799)
Use these constants across jsaction and Angular.

PR Close #55799
2024-05-23 16:10:47 +02:00
Thomas Nguyen
99bd9f13f8 refactor(core): Add a test case for content projection. (#55801)
This test actually used to fail until our recent improvements :))

PR Close #55801
2024-05-15 08:57:48 -07:00
Thomas Nguyen
629b255ddb refactor(core): Add four tests and fix code to make tests pass. (#55747)
The first test asserts that bubbling does not work right now.

The second asserts that stopPropagation works, which should pass when test #1 passes too.

The third test asserts properties about the events passed to the event handler.

THe fourth test asserts that mouse events do not translate to jsaction nor help emit the jsaction binary. This required a change in code to make this pass.

PR Close #55747
2024-05-14 09:38:43 -07:00
iteriani
28fb385eec refactor(core): Use early event contract instead of the event contract in bootstrap. (#55587)
This also fixes an existing bug where we erase the jsaction attribute too early.

Now the event contract binary is 608 bytes :D.

PR Close #55587
2024-05-09 14:34:10 -07:00
Alan Agius
8630dc8149 test: add Integration tests for hydration and event reply (#55708)
This commit introduces integration tests for hydration and event reply functionalities. Additionally, it implements a payload size check for the `event-dispatch-contract.min.js`.

PR Close #55708
2024-05-07 13:39:55 -07:00