Commit graph

2949 commits

Author SHA1 Message Date
Kristiyan Kostadinov
f280467398 fix(compiler-cli): account for multiple generated namespace imports in HMR (#58924)
The current HMR compiler assumes that there will only be one namespace import in the generated code (`@angular/core`). This is incorrect, because the compiler may need to generate additional imports in some cases (e.g. importing directives through a module). These changes adjust the compiler to capture all the namespaces in an array and pass them along.

Fixes #58915.

PR Close #58924
2024-11-28 10:00:56 +01:00
arielbackenroth
3b765367f3 fix(core): Explicitly manage TracingSnapshot lifecycle and dispose of it once it's been used. (#58929)
Provide a callback to the TracingService implementation when a Snapshot can be disposed.
The underlying tracing implementation may use refcounting and needs to release resources
to enable the trace to complete.

While change detection uses the snapshot for exactly one callback, after render runs
multiple hooks in the sequence so we need a more predictable way to indicate that the snapshot
can be finalized.s

PR Close #58929
2024-11-27 18:11:13 +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
Matthieu Riegler
901fd1c09b fix(core): Ensure resource sets an error (#58855)
Before this commit, a resource with a previous value wouldn't set the error state correctly.
This commit fixes this. A resource will set its status to error even when there was a previous valid value.

PR Close #58855
2024-11-25 15:28:17 +00: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
Kristiyan Kostadinov
7eeae9f170 refactor(core): adjust tracing service (#58771)
Adjusts the tracing service based on internal requirements.

PR Close #58771
2024-11-21 16:34:53 +00:00
Andrew Kushnir
a55341b1ab refactor(core): add REQUEST, RESPONSE_INIT and REQUEST_CONTEXT tokens (#58669)
This commit introduces the `REQUEST`, `RESPONSE_INIT` and `REQUEST_CONTEXT` tokens, which will replace similar ones from 2850318623/packages/angular/ssr/tokens/src/tokens.ts, so those tokens would be imported in application code via `@angular/core` package.

PR Close #58669
2024-11-14 14:21:21 -08:00
Jessica Janiuk
f3d9316275 refactor(core): moves incremental hydration codebase to better locations (#58616)
This eliminates the extra incremental.ts codepath and moves its functions to appropriate locations.

PR Close #58616
2024-11-12 22:25:27 +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
42c99763f5 refactor(core): reorganize defer codebase (#58598)
This moves all the helpers out of the instructions file, keeping the instructions limited to the actual instruction set. This adds files for defer block rendering functions and triggering functions, respectively.

PR Close #58598
2024-11-11 19:11:02 +00:00
Jessica Janiuk
47224fb3c1 refactor(core): clean up incremental code base (#58553)
This re-organizes the code to be a bit cleaner with no more need for the onTriggerFn function.

PR Close #58553
2024-11-11 14:35:36 +00:00
Kristiyan Kostadinov
b35ecee85e refactor(core): clean up standalone flag (#58478)
The `NG_STANDALONE_DEFAULT_VALUE` is no longer being patched internally and can be removed.

PR Close #58478
2024-11-06 07:01:25 +01:00
Kristiyan Kostadinov
4ef11c987d fix(core): resolve forward-referenced host directives during directive matching (#58492)
When the compiler generates the `HostDirectivesFeature`, it generates either an eager call (`ɵɵHostDirectivesFeature([])`) or a lazy call (`ɵɵHostDirectivesFeature(() => [])`. The lazy call is necessary when there are forward references within the `hostDirectives` array. Currently we resolve the lazy variant when the component definition is created which has been enough for most cases, however if the host is injected by one of its host directives, we can run into a reference error because DI is synchronous and the host's class hasn't been defined yet.

These changes resolve the issue by pushing the lazy resolution later during directive matching when all classes are guanrateed to exist.

Fixes #58485.

PR Close #58492
2024-11-04 16:17:23 +01:00
Kristiyan Kostadinov
21adbba784 fix(compiler): avoid having to duplicate core environment (#58444)
Switches to referencing the core environment directly in the generated code, instead of having to duplicate it.

PR Close #58444
2024-11-01 14:32:57 +00:00
Alan Agius
01fcbafa2b build: update cross-repo angular dependencies (#58446)
See associated pull request for more information.

Closes #57880 as a pr takeover

PR Close #58446
2024-10-31 19:05:01 +01:00
Andrew Kushnir
89db5f734d refactor(core): tree-shake defer block registry (#58424)
This commit updates the code of the incremental hydration feature to make the `DeferBlockRegistry` class tree-shakable. The class is only needed for hydration cases and it should not be included into client bundles for client-only apps.

PR Close #58424
2024-10-31 18:12:03 +01: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
Alan Agius
924e54ab4a test: update defer symbol test golden file (#58297)
Update the golden file of the defer symbol test

PR Close #58297
2024-10-28 12:26:05 -07:00
Alan Agius
b23e749b5e refactor(core): eliminate top-level property access in ɵɵNgOnChangesFeature (#58297)
Top-level property access was causing dead code elimination (DCE) and tree-shaking issues. This commit modifies `ɵɵNgOnChangesFeature` to prevent these bailouts.

PR Close #58297
2024-10-28 12:26:05 -07:00
Alan Agius
7de7c52769 build: remove usages of useDefineForClassFields: false (#58297)
When setting `"useDefineForClassFields": false`, static fields are compiled within a block that relies on the `this` context. This output makes it more difficult for bundlers to treeshake and eliminate unused code.

PR Close #58297
2024-10-28 12:26:05 -07:00
Jessica Janiuk
0f2f7ec754 refactor(core): cleanup incremental hydration code (#58363)
This cleans up some minor issues with the incremental hydration implementation and should make maintaining it a little easier.

PR Close #58363
2024-10-28 09:26:45 -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
Matthieu Riegler
bc9ef72fae refactor(compiler): update compliance tests. (#58238)
`standalone: true` is now the default at runtime.

PR Close #58238
2024-10-24 12:44:12 -07:00
Matthieu Riegler
a10f7cfbc2 refactor(core): Don't generate standalone: true for definitions (#58238)
The runtime default is now `standalone: true`.
`ɵɵdefineComponent`, `ɵɵdefineDirective` and `ɵɵdefinePipe` now set `standalone` as `true` by default in the definitions.

PR Close #58238
2024-10-24 12:44:12 -07:00
AleksanderBodurri
ec386e7f12 feat(core): introduce debugName optional arg to framework signal functions (#57073)
Angular DevTools is working on developing signal debugging support. This commit is a step in the direction of making available debug information to the framework that will allow Angular DevTools to provide users with more accurate information regarding the usage of signals in their applications.

Follow up PRs that will use this arg will:
- Develop a typescript transform that will detect usages of signal functions and attempt to add a debugName without the user needing to specify one directly
- Develop debug APIs for discovering signal graphs within Angular applications (using debugName as a way to label nodes on the graph)

PR Close #57073
2024-10-22 11:26:37 -07:00
Matthieu Riegler
308acb95c3 refactor(core): removing error related dead code. (#58272)
we're not invoking `wrappedError` any more, removing all the related code.

PR Close #58272
2024-10-22 09:42:47 -07:00
Younes Jaaidi
19edf2c057 feat(core): add syntactic sugar for initializers (#53152)
add helper functions provideAppInitializer, provideEnvironmentInitializer & providePlatformInitializer
to respectively simplify and replace the use of APP_INITIALIZER, ENVIRONMENT_INITIALIZER, PLATFORM_INITIALIZER

add a migration for the three initialiers

PR Close #53152
2024-10-22 09:38:18 -07:00
Alex Rickabaugh
18d8d44b1f feat(core): experimental resource() API for async dependencies (#58255)
Implement a new experimental API, called `resource()`. Resources are
asynchronous dependencies that are managed and delivered through the signal
graph. Resources are defined by their reactive request function and their
asynchronous loader, which retrieves the value of the resource for a given
request value. For example, a "current user" resource may retrieve data for
the current user, where the request function derives the API call to make
from a signal of the current user id.

Resources are represented by the `Resource<T>` type, which includes signals
for the resource's current value as well as its state. `WritableResource<T>`
extends that type to allow for local mutations of the resource through its
`value` signal (which is therefore two-way bindable).

PR Close #58255
2024-10-21 13:25:58 -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
Alan Agius
59ce1531d0 refactor(core): wrap AFTER_RENDER_PHASE_EFFECT_NODE in an IIFE for Tree-shaking (#58283)
Currently, `AFTER_RENDER_PHASE_EFFECT_NODE` is not tree-shakable. By wrapping it in an IIFE, it will be annotated as pure, allowing unused code to be removed during the tree-shaking process.

This issue was discovered while investigating: https://github.com/angular/angular-cli/issues/28676.

PR Close #58283
2024-10-21 09:07:54 -07:00
Pawel Kozlowski
8311f00faa feat(core): introduce the reactive linkedSignal (#58189)
This change introduces the new reactive primitive: linkedSignal.

A linkedSignal represents state (hence the signal in the name)
that is reset based on the provided computation. Conceptually
it is a state that is maintained / valid only in the context of
another source signal (context is deteremined by a computation).

Closes #55673

PR Close #58189
2024-10-18 08:12:51 +00:00
Pawel Kozlowski
dd407a7132 refactor(core): expose producerMarkClean utility (#58228)
This commit exposes the new producerMarkClean utility that
makes it possible to mark a reactive node as clean following
changes to the node's value. In practice it resets the dirty
flag and all other internal flags as need. Prior to this change
the cleanup code was duplicated.

The new utility will be used in the linkedSignal implementation.

PR Close #58228
2024-10-17 18:09:16 +00:00
Matthieu Riegler
141f3107e1 refactor(core): standalone by default for JIT compiled directives (#58236)
This commit fixes the standalone by default for JIT compiled directives (like in unit tests)

PR Close #58236
2024-10-17 13:26:21 +00:00
Matthieu Riegler
0c9d721ac1 feat(compiler): add support for the typeof keyword in template expressions. (#58183)
This commit adds the support for `typeof` in template expressions like interpolation, bindings, control flow blocks etc.

PR Close #58183
2024-10-16 07:31:00 +00:00
Kristiyan Kostadinov
1212f354a7 refactor(core): account for new replaceMetadata signature (#58205)
Updates the runtime code to account for the upcoming changes to `ɵɵreplaceMetadata`.

I also had to reorganize how the `angularCoreEnv` was set up, because `ɵɵreplaceMetadata` needs access to it without triggering a circular dependency.

PR Close #58205
2024-10-16 07:22:45 +00:00
Alex Rickabaugh
7f0b49d8c4 refactor(core): update effect error handling (#57952)
Previously, effect() would handle errors differently depending on the effect
type. Root effects had a try/catch that would execute them independently and
report errors to `ErrorHandler`, while component effects would "crash" CD.

This commit switches all effects to use the same error handling (errors
always reach the CD error handler).

An additional unrelated refactoring is thrown in which removes the
`pendingTask` machinery from root effects, since they make `ApplicationRef`
dirty and thus trigger the scheduler.

PR Close #57952
2024-10-15 13:02:10 -07:00
Jessica Janiuk
d760cbe71b refactor(core): Update interfaces for handling defer completion (#58206)
This adds properties to the LDeferBlockDetails and ensures the completion functions exist for future incremental hydration use cases.

PR Close #58206
2024-10-15 16:49:27 +00:00
Matthieu Riegler
a34090bc71 refactor(compiler): dynamic default for the partial compiler. (#58169)
Use `semver` in the partial compiler to decide on a default value

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

PR Close #58169
2024-10-15 16:05:14 +00:00
Jessica Janiuk
9224f9b043 refactor(core): Add mouseover to hover dom triggers (#58197)
Unfortunately mouseenter is a synthetic event, meaning it does not bubble in the same ways. So mouseover needs to be included in this list in order to get proper browser replayability of the mouse hovering events.

PR Close #58197
2024-10-14 14:27:04 -07:00
Matthieu Riegler
517da9532c refactor(core): Setup constant for standalone default value (#58175)
This commit is part of the migration to standalone by default and sets up 2 files with a default value for standalone. They are still `false` in this case to land the change into G3 first. The switch to `true` will be executed in a follow-up PR.

PR Close #58175
2024-10-14 16:01:41 +00: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
Kristiyan Kostadinov
fc6c76ac67 refactor(core): add internal utility to resolve the component name of a node (#58148)
Adds a utility, meant for internal consumption, that will return the class name of the closest component node to an element.

PR Close #58148
2024-10-11 07:04:40 +00:00
Kristiyan Kostadinov
67db4305c2 fix(core): clean up afterRender after it is executed (#58119)
We stop tracking `afterRender` hooks as soon as they execute, but their on destroy callbacks stay registered until either the injector is destroyed or the user calls `destroy` manually. This was leading to memory leaks in the `@defer` triggers based on top of `afterRender` when placed inside long-lived views, because the callback would execute, but its destroy logic was waiting for the view to be destroyed.

These changes resolve the issue by destroying the `AfterRenderRef` once it is executed.

PR Close #58119
2024-10-08 13:27:06 -07:00
P4
97fb86d331 perf(core): set encapsulation to None for empty component styles (#57130)
Make it so that encapsulation for empty styles, styles containing only whitespace and comments, etc.
is handled the same way as with no styles at all.

Components without styles already have view encapsulation set to `None`
to avoid generating unnecessary attributes for style scoping, like `_ngcontent-ng-c1` (#27175)

If the component has an empty external styles file instead, the compiler would generate
a component definition without the `styles` field, but still using the default encapsulation.
This can result in runtime overhead if the developer forgets to delete the empty styles file
generated automatically for new components by Angular CLI.

Closes #16602

PR Close #57130
2024-10-08 09:30:01 -07:00
Dylan Hunn
09f589f000 fix(compiler): this.a should always refer to class property a (#55183)
Consider a template with a context variable `a`:
```
<ng-template let-a>{{this.a}}</ng-template>
```

t push -fAn interpolation inside that template to `this.a` should intuitively read the class variable `a`. However, today, it refers to the context variable `a`, both in the TCB and the generated code.

In this commit, the above interpolation now refers to the class field `a`.

BREAKING CHANGE: `this.foo` property reads no longer refer to template context variables. If you intended to read the template variable, do not use `this.`.
Fixes #55115

PR Close #55183
2024-10-08 16:02:18 +00:00
Daniel Jancar
656b5d3e78 fix(core): Re-assign error codes to be within core bounds (<1000) (#53455)
`RUNTIME_DEPS_INVALID_IMPORTED_TYPE` is now 980
`RUNTIME_DEPS_ORPHAN_COMPONENT` is now 981

PR Close #53455
2024-10-07 08:21:13 -07: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
arturovt
b7bd429951 fix(common): prevent warning about oversize image twice (#58021)
I’ve noticed that there was a loop inside a loop. Since we’re already iterating through
`images` using `forEach`, it was running a `for` loop through `images` again. This was
probably a mistake made when the functionality was initially added. The test actually
verified that `logs.length` is `1`, but in the real environment, it logs twice
(which is quite obvious due to the code).

I’ve also added the missing file to the Bazel target.

PR Close #58021
2024-10-02 11:46:17 +00:00
Kristiyan Kostadinov
682da6f59f refactor(core): fix typo in function name (#57988)
Fixes a typo in the `replaceMetadata` function name.

PR Close #57988
2024-09-30 13:31:24 -07:00
arturovt
e8b2d5fad8 fix(common): skip checking whether SVGs are oversized (#57966)
Prior to this commit, the `ImagePerformanceWarning` class was checking all `img`
elements in the DOM to determine whether they were oversized after the DOM loading
was complete. We should not check SVGs because they are vector-based and can scale
infinitely without losing quality.

Closes #57941

PR Close #57966
2024-09-30 13:28:45 -07:00