Commit graph

5321 commits

Author SHA1 Message Date
Kristiyan Kostadinov
e170d24240 fix(core): add migration away from InjectFlags (#60318)
Adds an automated migration that will switch users from the deprecated `InjectFlags` API to its non-deprecated equivalent.

PR Close #60318
2025-03-11 11:33:09 -07:00
aparzi
de2bfc0913 fix(core): fix removal of a container reference used in the component file (#60210)
During migration a container reference was deleted even though it was used in the component file.

PR Close #60210
2025-03-11 09:26:13 -07:00
Matthieu Riegler
c73520bb74 refactor(compiler): remove empty empty string suffix from interpolation instructions (#60066)
With this change, interpolations that don't have a suffix will miss the last argument which was previously an empty string.

PR Close #60066
2025-03-10 16:31:34 -07:00
Matthieu Riegler
e3afa24089 refactor(core): log a warning instead of throwing error on OutputRef.emit when the directive is destroyed. (#60293)
This should not be a hard error, as nothing bad happens but the users should be warned that no event will be emitted.

fixes #60110

PR Close #60293
2025-03-10 16:08:52 -07:00
arturovt
f2a8006591 refactor(core): replace PLATFORM_ID in initTransferState (#60299)
Replaces `PLATFORM_ID` check with the `ngServerMode`.

PR Close #60299
2025-03-10 13:49:23 -07:00
Andrew Scott
ff772d7800 fix(core): fix typing on injector.get to omit 'any' (#60202)
This commit further restricts the deprecated type on injector.get to exclude
all but `string`. Progresses towards #48408

BREAKING CHANGE: The `any` overload has been removed from
`injector.get`. It now only supports `ProviderToken<T>` and (deprecated
since v4) `string`.

PR Close #60202
2025-03-10 13:48:18 -07:00
iteriani
e13f11db69 refactor(core): Create a function convertToInjectOptions and convert back to an options. This allows seamless back and forth from bitflags and options. (#60192)
Note that we do have to keep converting back and forth, but we'll see if that's a problem.

PR Close #60192
2025-03-10 11:38:13 -07:00
iteriani
92bb8d974b refactor(core): Use the retrieve method in the implementation of injectInjectorOnly (#60192)
This should keep the existing behavior intact. Right now retrieve never returns back NOT_FOUND. This should not be the case, but tests fail if I do add this behavior so itll have to be later.

PR Close #60192
2025-03-10 11:38:13 -07:00
Kristiyan Kostadinov
0e40a1c93f build: remove migrations for v19 (#60304)
Removes the migrations for v19 since they aren't relevant anymore.

PR Close #60304
2025-03-10 09:20:52 -07:00
Andrew Scott
338818ce89 fix(core): Surface errors from ApplicationRef.tick to callsite (#60102)
This commit ensures that errors during `ApplicationRef.tick` are
surfaced to the callsite rather than being caught and reported to the
`ErrorHandler`.

The current catch and report approach was originally
added in e263e19a2a
with the goal of preventing automatic change detection crashes due to
the error happening in the subscription. However, this results in hiding
a public API that can hide errors. Callers cannot assume that the tick
was successful and perform follow-up work.

This change now surfaces errors and adds the error handling directly to
the callsites.

BREAKING CHANGE: `ApplicationRef.tick` will no longer catch and report
errors to the appplication `ErrorHandler`. Errors will instead be thrown out of
the method and will allow callers to determine how to handle these
errors, such as aborting follow-up work or reporting the error and
continuing.

PR Close #60102
2025-03-10 08:17:14 -07:00
Alan Agius
9080fdf6f8 test: narrow down signal-input typescript tests (#60266)
Remove TS versions that are no longer supported.

PR Close #60266
2025-03-07 11:00:03 -08:00
Alan Agius
45f899a272 refactor: replace fast-glob usage with tinyglobby (#60264)
Usage of the `fast-glob` package has been replaced with the `tinyglobby` package. The change reduces the number of transitive dependencies related to these packages from 17 to 2 while also maintaining equivalent functionality. This was also changed in the Angular CLI packages.

PR Close #60264
2025-03-07 10:57:23 -08:00
Vlad Boisa
cc0bd25f3e docs: fix typo in desription (#60261)
Fix typos in description of `styleUrl`

Fixes #60258
PR Close #60261
2025-03-07 10:55:37 -08:00
Andrew Scott
02cb7e061a refactor(core): remove microtask effect (#60234)
This has been removed internally and was never exposed externally (it was a breaking change)

PR Close #60234
2025-03-06 12:48:55 -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
Pawel Kozlowski
39b324de67 refactor(core): drop render-related perf counters (#60200)
It looks like we are not getting enough value from having
those counters. This is an exploratory PR to see if thsoe
could be removed.

PR Close #60200
2025-03-06 10:33:54 -08:00
Jessica Janiuk
cae1fe519b fix(router): update symbols (#60233)
This updates the goldens for the router.

PR Close #60233
2025-03-05 15:34:05 -08:00
arturovt
5c70a048a9 refactor(core): add token to missing injection context error message (#60009)
In this commit, we add injector token information to the error message to improve debugging and context awareness, because it is hard to capture the `inject()` stack trace in asynchronous contexts.

PR Close #60009
2025-03-05 14:44:43 -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
iteriani
ac94604ef2 refactor(core): Remove the optional flag from Injector and all casts. (#60154)
Note that this does NOT use the retrieve method yet. I believe we need to move the logic for notFoundValue into the inject implementation.

PR Close #60154
2025-03-05 13:43:59 -08:00
Taygan Caldwell
1d3b9148d3 refactor: add untracked to primitives (#60105)
add untracked to primitives to allow Wiz to use it

PR Close #60105
2025-03-05 12:11:40 -08:00
arturovt
1124b8ff0d refactor(core): inline isFactory within getNodeInjectable (#59824)
This commit inlines the `isFactory` function body directly within `getNodeInjectable` because it is only used once. ESBuild does not inline its body within the function, which can be observed when running the build with `NG_BUILD_MANGLE=0`. The results after inlining are as follows:

```
getNodeInjectable x 70,397,377 ops/sec ±3.88% (52 runs sampled)
getNodeInjectable_inlined x 77,834,432 ops/sec ±3.13% (60 runs sampled)
```

PR Close #59824
2025-03-05 17:24:52 +00:00
arturovt
aa8dff80ba refactor(core): drop getNgModuleDef error message in production (#60082)
Drops `getNgModuleDef` error message in production and replaces it with an error code.

PR Close #60082
2025-03-05 17:11:06 +00:00
Emil Rowland
7eb59d3887 fix(core): added @angular/compiler as a peer dependency (#55610)
This fixes an issue with packages managers likes pmpm
that will not link the @angular/compiler package to the @angular/core
package if it is not listed as a peer dependency.
I added it as optional peer dependency as it's only used in special cases.

Fixes #38096

PR Close #55610
2025-03-04 22:06:59 +00:00
Andrew Scott
fd12220a35 fix(core): defer block render failures should report to application error handler (#60149)
This commit updates error reporting of defer blocks to go to the
application root error handler rather than the `ErrorHandler` token that
may be provided by users. This ensures Angular has control over what
happens when these errors are reported.

PR Close #60149
2025-03-04 22:06:17 +00:00
Matthieu Riegler
e605433f74 refactor(core): extract dirty and markForRefresh from the private ViewRef. (#59122)
This allows better tree shaking from projects without the `element` package.

PR Close #59122
2025-03-04 22:05:40 +00:00
Samuel Perez
6dd8cce155 docs: fix all brokens links on the API pages (#59162)
This PR fix is for the broken links on the API
pages mentioned in issue #57591.

PR Close #59162
2025-03-04 20:07:23 +00:00
Alexis
6f6d9f1e8a docs: Remove misleading default value DEFAULT_CURRENCY_CODE (#59977)
PR Close #59977
2025-03-04 19:37:57 +00:00
Matthieu Riegler
4aeec9fa7d refactor(core): throw an Cyclic Dependency Error in prod mode (#60118)
Prior to this change, cyclic injection didn't trigger any error in prod mode, resulting into injecting the `CIRCULAR` object.
This could lead to strange errors where no method would be found on the token.

fixes #60074

PR Close #60118
2025-03-04 19:37:19 +00:00
naaajii
b4feeb5a7d docs: update license year (#59883)
updates the year in footer and placeholder for generated files

PR Close #59883
2025-03-04 19:36:47 +00:00
hawkgs
2b114e784d docs(docs-infra): API doc content rendering fixes (#60116)
The PR introduces a few doc content rendering fixes:
- Fix highlighted section heading styles (regression from #59965).
- Convert JSDoc links within 'Usage Notes' sections to HTML and render them.
- Add IDs to doc content headings. This, by itself, makes these headings available in the page ToC.

PR Close #60116
2025-03-04 17:46:30 +00:00
Miles Malerba
2e03a8685b docs(docs-infra): Improve support for @link within the jsdoc. (#60201)
PR Close #60201
2025-03-04 17:13:42 +00:00
Pawel Kozlowski
809b5b4596 feat(core): introduce new DI profiling event (#60158)
This change introduces a new DI profiler event:
InjectorToCreateInstanceEvent. This new event allows
us to measure DI tokens instantiation time.

PR Close #60158
2025-03-03 22:06:50 +00:00
Kristiyan Kostadinov
a3cb7b9497 refactor(core): allow InputBinding and OutputBinding to be tree shaken (#60137)
Reworks the `InputBinding` and `OutputBinding` functionality to be in object literals constructed in functions, rather than classes, because it seems like Terser was having a hard time tree shaking the classes when the functions weren't used.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
be44cc8f40 feat(core): support listening to outputs on dynamically-created components (#60137)
Adds the new `outputBinding` function that allows users to listen to outputs on dynamically-created components in a similar way to templates. For example, here we create an instance of `MyCheckbox` and listen to its `onChange` event:

```ts
interface CheckboxChange {
  value: string;
}

createComponent(MyCheckbox, {
  bindings: [
   outputBinding<CheckboxChange>('onChange', event => console.log(event.value))
  ],
});
```

Note that while it has always been possible to listen to events like this by getting a hold of of the instance and subscribing to it, there are a few key differences:
1. `outputBinding` behaves in the same way as if the event was bound in a template which comes with some behaviors like forwarding errors to the `ErrorHandler` and marking the view as dirty.
2. With `outputBinding` the listeners will be cleaned up automatically when the component is destroyed.
3. `outputBinding` accounts for host directive outputs by binding to them through the host. E.g. if the `onChange` event above was coming from a host directive, `outputBinding` would bind to it automatically.

Currently `outputBinding` is available only in `createComponent`, `ViewContainerRef.createComponent` and `ComponentFactory.create`, but it will serve as a base for APIs in the future.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
3459faadbf fix(core): do not allow setInput to be used with inputBinding (#60137)
Calling `setInput` while the component already has an `inputBinding` active can lead to inconsistent state. These changes add an error that will be thrown if that's the case.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
fe57332fc5 feat(core): add input binding support to dynamically-created components (#60137)
Adds the ability to bind to inputs on dynamically-created components, either by targeting the component itself or one of its directives. The new API looks as follows:

```ts
const value = signal(123);

createComponent(MyComp, {
  // Bind the value `'hello'` to `someInput` of `MyComp`.
  bindings: [inputBinding('someInput', () => 'hello')],

  directives: [{
    type: MyDir,
    // Bind the `value` signal to the `otherInput` of `MyDir`.
    bindings: [inputBinding('otherInput', value)]
  }]
});
```

This behavior overlaps with `ComponentRef.setInput`, with a few key differences:
1. `setInput` sets the value on *all* inputs whereas `inputBinding` only targets the specified directive and its host directives. This makes it easier to know which directive you're targeting.
2. `inputBinding` is executed as if it's in a template, making it consistent with how bindings behave for selector-matched components, whereas `setInput` executes outside the lifecycle of the component.
3. It resolves a long-standing issue with `setInput` where it wasn't possible to set the initial value of an input before the first change detection run.

Currently `inputBinding` is used only for `createComponent`, `ViewContainerRef.createComponent` and `ComponentFactory.create`, however it is going to be base for more APIs in the future.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
ea5eb28865 fix(core): input targeting not checking if input exists on host (#60137)
Fixes that the `setDirectiveInput` function wasn't checkin if an input exists before writing to it which can lead to assertion errors.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
a97e10d623 refactor(core): set up underlying input binding symbols (#60137)
Sets up the symbols used to power the upcoming `inputBinding` functionality.

I also fixed that `setDirectiveInput` was incorrectly only allowing strings for the `value` parameter.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
82aa2c1a52 feat(core): add the ability to apply directives to dynamically-created components (#60137)
Updates `createComponent`, `ViewContainerRef.createComponent` and `ComponentFactory.create` to allow the user to specify directives that should be applied when creating the component.

PR Close #60137
2025-03-03 22:04:49 +00:00
Kristiyan Kostadinov
25cae4555a refactor(core): add assertion parameter to getDirectiveDef (#60137)
Some upcoming functionality won't work if we can't retrieve a directive definition from a class. These changes add a `throwIfNotFound` to `getDirectiveDef`, similar to `getNgModuleDef`, to avoid duplication in such cases.

PR Close #60137
2025-03-03 22:04:48 +00:00
Kristiyan Kostadinov
2b12b8a569 refactor(core): move duplicate directive check outside of host directives (#60137)
The check that verifies that there are no duplicates in the directives array was only running after host directive matching since that was the only case when it can happen. After the upcoming changes that won't be the case anymore so these changes move it always run after directive matching.

I also did some additional cleanup by adding comments and by not lazily initializing the `allDirectiveDefs` array when matching host directives. The array is guaranteed to be defined since earlier in the function we verify that there's at least one def with host directives.

PR Close #60137
2025-03-03 22:04:48 +00:00
Kristiyan Kostadinov
93304630a7 refactor(core): move createComponent tests into a separate file (#60137)
Moves the tests for `createComponent` into their own file since the `component_spec.ts` was a bit too generic and was accumulating all sorts of tests.

PR Close #60137
2025-03-03 22:04:48 +00:00
AleksanderBodurri
d260ca3091 feat(core): emit template function for template related profiler hooks (#60174)
Previously, the profiler would only emit the specific template event and context when a template is created/updated, but not the template function related to the event.

This commit emits this function by using the third argument of the profiler function, which previously was only used for lifecycle hooks and output listeners. This commit also renames this arg to eventFn to express that it varies depending on the event type emitting from the profiler.

Note: this change is fully backwards compatible, since previously these template events did not use the third arg of the profiler function.

PR Close #60174
2025-03-03 22:03:44 +00:00
Andrew Scott
a3575e204a refactor(core): Update push/replace navigation to not trigger popstate (#60028)
This matches the spec, though there is a bug in chrome that does trigger these events.

PR Close #60028
2025-03-03 18:40:58 +00:00
Andrew Scott
2e8b84f086 refactor(core): Update fake navigation to more closely follow the spec (#60028)
This commit updates the implementation of the fake navigation to more
closely follow the spec. This includes links to spec parts as well as
some reorganization to have the flow of the code more exactly follow the
corresponding steps in the spec. This makes it easier to verify that th
behavior is correct.

PR Close #60028
2025-03-03 18:40:58 +00:00
Andrew Scott
ae9c7225d4 refactor(core): Ensure fake navigation is not aborted after it succeeds (#60028)
The navigate event was only ever being cleared when a new navigation
happened. That new navigation would abort the previous one, even if it
had already finished successfully.

PR Close #60028
2025-03-03 18:40:58 +00:00
Andrew Scott
7232ce5b17 fix(core): Catch and report rejections in async function of PendingTasks.run (#60044)
This commit ensures that rejections of the promise of the async function
passed to `PendingTasks.run` are not dangling and get reported to the
application error handler. This prevents what would likely be a common
dangling promise that could end up crashing the node process.

BREAKING CHANGE: `PendingTasks.run` no longer returns the result of the
async function. If this behavior is desired, it can be re-implemented
manually with the `PendingTasks.add`. Be aware, however, that promise rejections
will need to be handled or they can cause the node process to shut down
when using SSR.

PR Close #60044
2025-03-03 17:13:33 +00:00
Miles Malerba
51b8ff23ce feat(compiler): support tagged template literals in expressions (#59947)
Adds support for using tagged template literals in Angular templates.

Ex:
```
@Component({
  template: '{{ greet`Hello, ${name()}` }}'
})
export class MyComp {
  name = input();

  greet(strings: TemplateStringsArray, name: string) {
    return strings[0] + name + strings[1] + '!';
  }
}
```

PR Close #59947
2025-02-28 19:53:33 +00:00
iteriani
78b27a83fb refactor(core): Move getCurrentInjector/setCurrentInjector to primitives package. (#60090)
This change casts the injector back and forth since all instances of
injector currently don't implement the `retrieve` method. Note that
the retrieve method is seen as optional, so that Angular can revert back to
inject if necessary.

PR Close #60090
2025-02-28 18:47:08 +00:00