Commit graph

286 commits

Author SHA1 Message Date
Paul Gschwendtner
810b0a7e5c refactor: add explicit types for exports relying on inferred call return type (#61312)
As part of the Bazel toolchain migration we noticed that implicit types
generated by the TypeScript compiler sometimes end up referencing types
from other packages (i.e. cross-package imports).

These imports currently work just because the Bazel `ts_library` and
`ng_module` rules automatically inserted a `<amd-module
name="@angular/x" />` into `.d.ts` of packages. This helped TS figure
out how to import a given file. Notably this is custom logic that is not
occuring in vanilla TS or Angular compilations—so we will drop this
magic as part of the toolchain cleanup!

To improve code quality and keep the existing behavior working, we are
doing the following:

- adding a lint rule that reduces the risk of such imports breaking. The
  failure scenario without the rule is that API goldens show unexpected
  diffs, and types might be duplicated in a different package!

- keeping the `<amd-module` headers, but we manually insert them into
  the package entry-points. This should ensure we don't regress
  anywhere; while we also improved general safety around this above.

Long-term, isolated declarations or a lint rule from eslint-typescript
can make this even more robust.

PR Close #61312
2025-05-13 22:45:18 +00:00
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
Jan Martin
06d6da345f fix(platform-server): less aggressive ngServerMode cleanup (#61106)
Other code may depend on `ngServerMode` and it might have been set
globally / via a bundler. Forcing it to `undefined` in those situations
can lead to hard debug issues where the only symptom is that "suddenly"
browser-specific code paths run on the server and (obviously) break.

PR Close #61106
2025-05-06 09:08:47 -07:00
Andrew Scott
e7f5aa2b52 refactor(core): Remove use of private export PendingTasksInternal where possible (#61049)
This commit removes the use of the privately exported
PendingTasksInternal everywhere except for Router. A follow-up change
will be done to remove that one as well and delete the private export.

PR Close #61049
2025-05-05 08:56:20 -07:00
arturovt
624be2ef0c fix(core): prevent stash listener conflicts (#59635)
The stash event listener is a global function that might be unsafely overridden if multiple microfrontend applications exist on the page.

In this commit, we create a map of `APP_ID` to stash event listener functions. This map prevents conflicts because multiple applications might be bootstrapped simultaneously on the client (one rendered on the server and one rendering only on the client).

I.e., the code that might be used is:

```ts
// Given that `app-root` is rendered on the server
bootstrapApplication(AppComponent, appConfig);

bootstrapApplication(BlogRootComponent, appBlogConfig);
```

Two bootstrapped applications would conflict and override each other's code.

PR Close #59635
2025-04-30 08:53:06 -07:00
Pawel Kozlowski
d8fbb909ce feat(core): rename afterRender to afterEveryRender and stabilize (#60999)
This change renames the afterRender to afterEveryRender and marks the
renamed API as stable.

BREAKING CHANGE: afterRender was renamed to afterEveryRender.

PR Close #60999
2025-04-28 12:33:55 -07:00
Andrew Kushnir
c2987d8402 refactor(core): stop producing ng-reflect attributes by default (#60973)
BREAKING CHANGE:

This commit deprecates `ng-reflect-*` attributes and updates the runtime to stop producing them by default. Please refactor application and test code to avoid relying on `ng-reflect-*` attributes.

To enable a more seamless upgrade to v20, we've added the `provideNgReflectAttributes()` function (can be imported from the `@angular/core` package), which enables the mode in which Angular would be producing those attribites (in dev mode only). You can add the `provideNgReflectAttributes()` function to the list of providers within the bootstrap call.

PR Close #60973
2025-04-24 10:07:35 -07:00
Andrew Scott
953c4b2580 feat(core): Move zoneless change detection to dev preview (#60748)
This commit moves zoneless from experimental to developer preview.

* Update tag on provider API
* Remove "experimental" from provider name
* Move documentation from "experimental features" to "Best practives ->
  Performance" (at least temporarily until there is a better place)

BREAKING CHANGE: `provideExperimentalZonelessChangeDetection` is
renamed to `provideZonelessChangeDetection` as it is now "Developer
Preview" rather than "Experimental".

PR Close #60748
2025-04-23 11:47:56 +02:00
arturovt
1c7b356625 fix(core): release hasPendingTasks observers (#59723)
In this commit, we unsubscribe the `hasPendingTasks` subject to remove all active observers and enable granular garbage collection, as users may forget to unsubscribe manually when subscribing to `isStable`.

PR Close #59723
2025-04-02 18:26:06 +00:00
Andrew Kushnir
f773e08ee5 refactor(platform-server): switching to relative imports within the platform-server package (#60559)
This commit updates scripts within `packages/platform-server` to relative imports as a prep work to the upcoming infra updates.

PR Close #60559
2025-03-27 18:31:51 +00:00
Jessica Janiuk
13d1c8ab38 fix(core): fixes timing of hydration cleanup on control flow (#60425)
This properly cleans up stale control flow branches in the case
that branches change between server and client at the same
timing as NgIf / NgSwitch.

fixes: #58670
fixes: #60218

PR Close #60425
2025-03-21 14:45:23 -07:00
Jessica Janiuk
a920f87b1c ci: fix timer test flakiness (#60310)
This replaces the TimerScheduler entirely and ensures the callback is called immediately. This should prevent any further flakiness.

PR Close #60310
2025-03-10 15:08:54 -07:00
Jessica Janiuk
8e4d622799 ci: fix flakey timer tests (#60254)
This adjusts the tests to have a longer await time and removes the click portion of the test. These tests should only pass if the timer has triggered hydration.

PR Close #60254
2025-03-06 12:49:47 -08:00
Jessica Janiuk
c82384104f fix(core): ensures immediate trigger fires properly with lazy loaded routes (#60203)
In the case that a route was lazy loaded, some triggers would never properly finish hydrating due to things firing before the route finished resolving.
This will find the topmost parent defer block and ensure the registry knows about it before trying to hydrate.
In the case that the registry does not yet know, just the affected triggers await app stability before initializing.
fixes #59997

PR Close #60203
2025-03-06 12:47:46 -08:00
arturovt
79ae35577e fix(core): check whether application is destroyed before initializing event replay (#59789)
In this commit, we check whether the application is destroyed before initializing event replay. The application may be destroyed before it becomes stable, so when the `whenStable` resolves, the injector might already be in a destroyed state. As a result, calling `injector.get` would throw an error indicating that the injector has already been destroyed.

PR Close #59789
2025-03-05 14:43:47 -08:00
Jessica Janiuk
7ab0a8d1e7 fix(core): prevents event replay from being called on comment nodes (#60130)
In some rare cases with directives, it is possible that the stash function might be called on a comment node. This actually verifies that the node is an element and exits otherwise.

fixes: #60070

PR Close #60130
2025-02-28 16:30:27 +00:00
Jessica Janiuk
8a73327ba0 refactor(core): clean up event replay tests (#60130)
This updates the event replay tests to make them share the structure and utility functions used by hydration tests. This also resolves some soft errors in the event replay tests.

PR Close #60130
2025-02-28 16:30:27 +00:00
Jessica Janiuk
6e1ead6f93 refactor(core): clean up when blocks fail to fetch or hydrate (#59740)
There are cases where resources fail to fetch or the DOM has changed due to an if block. This should clean up the remaining promises and any registry references to those blocks in that case.

PR Close #59740
2025-02-21 11:08:03 -05:00
Jessica Janiuk
1ebf7bfb23 ci: fix flakey incremental hydration test (#59945)
This extends the test timeout for the two timer tests while shortening the actual hydrate on timer. This hopefully should result in more reliable CI.

PR Close #59945
2025-02-13 22:35:04 +00:00
Miles Malerba
6789c7ef94 fix(core): Defer afterRender until after first CD (#59455) (#59551)
This reverts commit ac2dbe3eb1.

PR Close #59551
2025-02-12 12:20:04 -08:00
Kristiyan Kostadinov
ea2ea5e65b test(core): update tests that were relying on implicit animations module (#59762)
We had some tests that were relying on the fact that the server module was importing animations implicitly.

PR Close #59762
2025-01-29 10:52:18 -08:00
arturovt
cf9054248d fix(core): check whether application is destroyed before printing hydration stats (#59716)
In this commit, we check whether the application is destroyed before printing hydration stats. The application may be destroyed before it becomes stable, so when the `whenStableWithTimeout` resolves, the injector might already be in a destroyed state. As a result, calling `injector.get` would throw an error indicating that the injector has already been destroyed.

PR Close #59716
2025-01-29 08:43:34 -08:00
Jessica Janiuk
f862ace181 fix(core): fixes test timer-based test flakiness in CI (#59674)
This converts two tests that rely on timers to use fakeAsync. This resolves the flakiness.

PR Close #59674
2025-01-22 13:27:05 -08:00
Pawel Kozlowski
35e5bbb0dc refactor(core): reuse setupStaticAttributes in ComponentRef (#59572)
This change refactor how the dynamically created component
deals with attributes in order to reuse the existing
setupStaticAttributes logic (instead of having specific
and similar code).

PR Close #59572
2025-01-17 09:59:59 -08:00
Andrew Kushnir
4e6017a9f5 test(platform-server): fix flaky incremental hydration test (#59584)
This commit updates a test setup to define a global `ngServerMode` correctly for a test that was emulating client-only behavior. The flag could've been set by prior tests and depending on its state, the test was acting differently.

PR Close #59584
2025-01-17 10:45:37 +01:00
Andrew Kushnir
8ea691a9d8 test(platform-server): fix flaky hydration test (#59579)
This commit updates testing setup logic to apply correct `document` reference, which should be used by the runtime. Previously, the timing of that operation was less predictable and in some cases led to reusing document state from previous tests.

PR Close #59579
2025-01-17 10:30:51 +01:00
arturovt
f6e97763cf fix(core): cleanup _ejsa when app is destroyed (#59492)
In this commit, we delete `_ejsa` when the app is destroyed, ensuring that no elements are still captured in the global list and are not prevented from being garbage collected.

PR Close #59492
2025-01-16 13:56:28 -08:00
Andrew Kushnir
ed05cb5695 refactor(core): do not serialize parent block id for top level blocks (#59190)
This commit updates incremental hydration-related annotation logic to avoid serializing parent block id when it's `null` (for top-level blocks).

PR Close #59190
2025-01-14 11:06:58 -05:00
Andrew Kushnir
ac2dbe3eb1 Revert "fix(core): Defer afterRender until after first CD (#58250)" (#59455)
This reverts commit 9870b643bf.

PR Close #59455
2025-01-09 14:30:01 -05:00
RafaelJCamara
5c9e84acd6 docs: update license URL from angular.io to angular.dev and year of license to 2025 (#59407)
PR Close #59407
2025-01-09 10:27:54 -05:00
Miles Malerba
9870b643bf fix(core): Defer afterRender until after first CD (#58250)
For `afterRender`/`afterNextRender` calls associated with a particular
view, ensure that they are not registered until after the first time the
view is rendered.

Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>

PR Close #58250
2025-01-08 15:33:38 +00:00
Andrew Kushnir
dc8280d950 Revert "refactor(platform-server): reduce timeout used in tests (#59275)" (#59380)
This reverts commit 19ec8266d1.

PR Close #59380
2025-01-06 17:24:26 +00:00
Andrew Kushnir
19ec8266d1 refactor(platform-server): reduce timeout used in tests (#59275)
This commit updates the timeout used in the incremental hydration tests from `101` -> `10` ms, which allows to speed up tests by ~20% (12.5 -> 10 seconds locally).

PR Close #59275
2025-01-06 16:18:58 +00:00
Jessica Janiuk
4a2df5628a refactor(core): add skipped defer blocks count to ngDevMode (#59188)
This adds the skipped defer blocks to the counts in ngDevMode and the logged hydration information.

PR Close #59188
2024-12-16 10:25:45 -08:00
Andrew Kushnir
1f4ff2fa36 fix(core): avoid triggering on timer and on idle on the server (#59177)
This commit updates defer block logic to avoid triggering `on idle` and `on timer` on the server for regular SSR mode (when incremental hydration is not enabled). Triggering the mentioned condition resulted in invoking `setTimeout` calls, which delayed serialization on the server during SSR (the process was waiting for the timeouts to clear).

PR Close #59177
2024-12-13 10:10:27 -08:00
Jessica Janiuk
cf89f14766 fix(core): Fix nested timer serialization (#59173)
There were type mismatches and or unintended any types that were preventing nested timers from accessing the delay value during hydration annotation processing.

PR Close #59173
2024-12-12 14:55:28 -08:00
kirjs
300b141cc8 fix(platform-server): Warn user when transfer state happens more than once (#58935)
This can happen if server providers are provided more than twice. We detect it on the state transfer phase by flagging app id as transferred in a set.

Resolves #58531

PR Close #58935
2024-12-12 14:47:28 -08:00
Alan Agius
24e317cb15 refactor: replace ɵPendingTasks with ɵPendingTasksInternal (#59138)
This commits remove usage of the old export.

PR Close #59138
2024-12-10 13:45:07 -08: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