Commit graph

582 commits

Author SHA1 Message Date
arturovt
ef10aa4005 feat(common): support decoding in NgOptimizedImage (#61905)
This commit adds the ability to set the decoding attribute in NgOptimizedImage. It proxies the binding onto the host image element. If no binding is provided, it defaults to "auto", which matches the browser's default behavior. This approach avoids any breaking changes resulting from the update.

PR Close #61905
2025-06-09 09:02:17 -07:00
Rafal Slawik
82327f2092 feat(common): accept undefined inputs in NgTemplateOutlet (#61404)
Extend types of inputs to include `undefined` to avoid `?? null` when using singals (e.g. `viewChild`).

Fixes #51225

PR Close #61404
2025-05-25 14:26:42 -07:00
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
Miles Malerba
c0e9fc103f docs: rename @nodoc to @docs-private (#61194)
This aligns with how angular/components marks their hidden APIs.
`@nodoc` has been broken since the switch to adev, this change should
properly hide the APIs again.

PR Close #61194
2025-05-09 10:23:00 -07:00
Matthieu Riegler
f580318411 docs(docs-infra): Add version of introduction for APIs (#60814)
For new APIs we'll mention since when a particular API is in its current status (experimental, devPreview, stable)

fixes #49668

PR Close #60814
2025-05-02 07:51:33 -07:00
Andrew Scott
88858118ea refactor(common): Mark inputs of deprecated control flow directives as deprecated (#61089)
This updates the inputs of the deprecated control flow directives as also deprecated.
Helpful for language services/tokenization tools

PR Close #61089
2025-05-01 14:59:25 -07:00
arturovt
1bbf75017c fix(common): cleanup updateLatestValue if view is destroyed before promise resolves (#58041)
According to the promise specification, promises are not cancellable by default.
Once a promise is created, it will either resolve or reject, and it doesn't
provide a built-in mechanism to cancel it.
There may be situations where a promise is provided, and it either resolves after
the pipe has been destroyed or never resolves at all. If the promise never
resolves — potentially due to factors beyond our control, such as third-party
libraries — this can lead to a memory leak.
When we use `async.then(updateLatestValue)`, the engine captures a reference to the
`updateLatestValue` function. This allows the promise to invoke that function when it
resolves. In this case, the promise directly captures a reference to the
`updateLatestValue` function. If the promise resolves later, it retains a reference
to the original `updateLatestValue`, meaning that even if the context where
`updateLatestValue` was defined has been destroyed, the function reference remains in memory.
This can lead to memory leaks if `updateLatestValue` is no longer needed or if it holds
onto resources that should be released.
When we do `async.then(v => ...)` the promise captures a reference to the lambda
function (the arrow function).
When we assign `updateLatestValue = null` within the context of an `unsubscribe` function,
we're changing the reference of `updateLatestValue` in the current scope to `null`.
The lambda will no longer have access to it after the assignment, effectively
preventing any further calls to the original function and allowing it to be garbage collected.

If Chrome is built with additional flags and run with `--allow-natives-syntax --track-retaining-path`,
we could use `%DebugTrackRetainingPath` to see the distance from the root for `updateLatestValue`
if it's passed directly to async.then, e.g.:

```js
%DebugTrackRetainingPath(updateLatestValue);

// Distance from root 4: 0x123456789abc <JSPromise (sfi = 0x1fbb02e2d7f1)>
```

PR Close #58041
2025-05-01 14:53:13 -07:00
arturovt
98e53ccfb8 refactor(common): drop platform check in LCPImageObserver (#59742)
Replaces platform check within the `LCPImageObserver` with the `ngServerMode` global.

PR Close #59742
2025-04-30 12:40:41 -07:00
Andrew Scott
b7d3f3dbfc feat(common): Allow passing ScrollOptions to ViewportScroller (#61002)
Adds ScrollOptions as an option second argument to ViewportScroller
scrollTo* functions.

Part of changes needed to address #58258

PR Close #61002
2025-04-29 12:23:12 -07:00
Andrew Seguin
8df787e7d5 docs: fix ngFor deprecation error message parsing (#61024)
PR Close #61024
2025-04-29 12:15:17 -07:00
Alan Agius
f2b22b01cc refactor(common): eliminate redundant iterator-to-array conversion (#60884)
Simplifies code by removing unnecessary `Array.from` usage.

PR Close #60884
2025-04-16 12:44:35 -04:00
Alan Agius
cbbea70fa3 fix(common): issue a warning instead of an error when NgOptimizedImage exceeds the preload limit (#60879)
This should not be treated as a hard error, as it doesn’t break the application but merely degrades performance.

Closes #60871

PR Close #60879
2025-04-16 12:01:26 -04:00
arturovt
ad5fbd944d refactor(common): drop value not a number message in production (#60699)
Drops value not a number message in production.

PR Close #60699
2025-04-02 19:20:11 +00:00
TJ Lavelle
b927ce8ec9 refactor(common): update AsyncPipe to explicitly accept PromiseLike only (#60551)
With the fixed in g3, we can keep the type limited to PromiseLike
instead of Promise|PromiseLike

PR Close #60551
2025-04-01 17:56:39 +00:00
TJ Lavelle
301996e0b4 refactor(common): update AsyncPipe to explicitly accept Promise | PromiseLike (#60551)
There is a chance that external users have "extended" AsyncPipe and are expecting to
pass in a Promise instance.

PR Close #60551
2025-04-01 17:56:39 +00:00
TJ Lavelle
c8c828ee58 refactor(common): update AsyncPipe to support PromiseLike (#60551)
Updates the AsyncPipe to work with PromiseLike, in addition to Promise.

PR Close #60551
2025-04-01 17:56:39 +00:00
Kristiyan Kostadinov
7ccec1494f feat(core): move DOCUMENT token into core (#60663)
Moves the `DOCUMENT` token from `common` into `core` since it's relevant for lots of SSR use cases and users shouldn't have to install `common` for it. The token is still exported through `common` for backwards compatibility.

PR Close #60663
2025-04-01 12:48:06 +00:00
Matthieu Riegler
51c303a45c refactor(core): remove TODOs referencing #24571 (#60648)
Fixing those todos are now mostly breaking changes.
The situation is "good" as is.

PR Close #60648
2025-03-31 20:24:29 +00:00
arturovt
5317979738 refactor(common): drop error messages in production (#60415)
Drops more error messages in production.

PR Close #60415
2025-03-31 18:08:37 +00:00
Matthieu Riegler
b407157ee8 refactor(core): Deprecate the structural directives ngIf/ngFor/ngSwitch. (#60492)
Note: This is not a deprecation of structural directives, this only about  `ngIf`/`ngFor`/`ngSwitch`.

DEPRECATED: `ngIf`/`ngFor`/`ngSwitch` are deprecated. Use the control flow blocks instead (`@for`/`@if`/`@switch`).

PR Close #60492
2025-03-28 15:46:41 +00:00
Kristiyan Kostadinov
785a1110e6 fix(common): resolve host binding type issues (#60481)
Fixes type issues in the host bindings of `NgOptimizedImage`.

PR Close #60481
2025-03-20 11:55:52 -07:00
arturovt
3602c536e4 refactor(common): drop error messages in production (#60242)
Drops more error messages in production.

PR Close #60242
2025-03-10 10:04:03 -07:00
arturovt
0f3fa5a2af refactor(common): drop ngIf assert template error in production (#59705)
This commit removes the `assertTemplate` error message in production.

PR Close #59705
2025-03-05 14:42:18 -08: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
Andrew Scott
739cadae62 fix(common): Handle errors in async pipe subscriptions (#60057)
`AsyncPipe` would previously promise rejections unhandled and
subscription errors uncaught. This is more or less fine in a Zone-based
application because errors inside the Angular Zone are caught be the
Zone's error trap and reported to `ErrorHandler`. However, in zoneless
applications, these errors are never caught or reported by the FW and
can reach the node process in SSR and cause it to shut down.

BREAKING CHANGE: `AsyncPipe` now directly catches unhandled errors in
subscriptions and promises and reports them to the application's
`ErrorHandler`. For Zone-based applications, these errors would have
been caught by ZoneJS and reported to `ErrorHandler` so the result is
generally the same. The change to the exact mechanism for reporting can
result in differences in test environments that will require test
updates.

PR Close #60057
2025-03-04 17:35:01 +00:00
Stephen Hicks
74cceba587 feat(common): throw error for suspicious date patterns (#59798)
Adjusts the date pipe and formatDate function to detect suspicious usages of the week-numbering year formatter without including the week number, as this is often confused for the calendar year and likely to result in incorrect results near New Years, meaning that those issues aren't typically caught during development. This commit starts throwing a development-only error to reveal this issue right away.

BREAKING CHANGE:

Using the `Y` formatter (week-numbering year) without also including `w` (week number) is now detected as suspicious date pattern, as `y` is typically intended.

PR Close #59798
2025-02-24 17:15:03 -05:00
Andrew Scott
8657a0e4cc refactor(core): Add fake navigation to primitives for code sharing (#59857)
This moves the `FakeNavigation` implementation to the primitives folder
so its implementation can be shared with Wiz. This class was initially
copied directly from the Wiz implementation, with some small modifications.
There will still need to be some work done to align the implementations
and fix anything internally that needs adjusting.

PR Close #59857
2025-02-19 20:09:10 +00:00
arturovt
40dc99da9c refactor(common): inline supports check in slice pipe (#59684)
The refactored version improves the original code by removing the `supports` method from the prototype and inlining the logic directly into the `transform` method. This reduces indirection and simplifies the class, especially since `supports` is not reused elsewhere. ESBuild can directly inline the condition into the `if` statement by removing the variable: `if (!("string" == typeof e || Array.isArray(e))) throw i(s, e);`.

PR Close #59684
2025-02-19 15:22:49 +00:00
arturovt
967488247e refactor(common): simplify stripTrailingSlash (#59746)
The new version of the function is smaller, eliminating extra bytes. The refactor improves both code size and readability while optimizing the implementation. Benchmark results for the old and new implementations are as follows:

```
stripTrailingSlash_old x 15,446,602 ops/sec ±0.89% (66 runs sampled)
stripTrailingSlash_new x 19,694,523 ops/sec ±1.10% (61 runs sampled)
```

Thus, the new implementation is both smaller and faster.

PR Close #59746
2025-02-19 15:20:53 +00:00
arturovt
762e56e210 refactor(common): drop platform check in PreconnectLinkChecker (#59714)
Replaces platform check within the `PreconnectLinkChecker` with the `ngServerMode` global.

PR Close #59714
2025-01-27 17:22:43 +01:00
arturovt
10cdf0afae refactor(common): tree-shake PreloadLinkCreator for client bundles (#59431)
In this commit, we tree-shake the `PreloadLinkCreator` for client bundles because it's targeting only server code. We use the pending tasks service to contribute to app stability by waiting for the module to load.

PR Close #59431
2025-01-24 17:17:58 +01:00
arturovt
d634ca7633 refactor(common): simplify joinWithSlash (#59484)
The new version is 2x smaller in the reduced code size; as thus this eliminates extra bytes. Refactors `joinWithSlash` function to reduce code size and improve readability. Added checks to handle leading and trailing slashes more concisely and provided comments for clarity.

PR Close #59484
2025-01-24 17:16:11 +01:00
arturovt
edb8407d4f refactor(common): simplify null/undefined check in keyvalue pipe (#59696)
In this commit, we remove the separate `a === undefined` and `a === null` checks and replace them with `a == null`. Using `a == null` is better and more concise because it checks for both `null` and `undefined` in a single operation. The loose equality `==` is specifically designed to treat `null` and `undefined` as equivalent. This change only reduces some bytes in the code and simplifies it, with no performance impact, as modern JavaScript engines handle `a == null` efficiently. Additionally, comments have been added for clarification.

PR Close #59696
2025-01-24 12:45:04 +01:00
Matthieu Riegler
d797c5cb94 docs: update class & style binding recommendation (#59240)
This commit introduces an update to the official recommendations when it comes to class & styles bindings.

`[class]` & `[style]` bindings are now recommended for basic uses cases.

`[ngClass]` and `[ngStyle]` allow more advanced bindings (like space separated keys) or keys with units (for `ngStyle`) which are not supported by the native bindings. They still require the dedicated directives.

PR Close #59240
2025-01-15 12:27:12 -05:00
hawkgs
b9155b5121 docs: set syntax highlighting to the remaining Markdown code examples blocks (#59088)
There are some code blocks that slipped through the initial Regex-es.

Related to #59026

PR Close #59088
2025-01-14 15:14:02 -05:00
arturovt
bc77f44802 refactor(common): tree-shake lcpObserver in NgOptimizedImage (#59481)
Prior to this commit, the `this.lcpObserver?.updateImage` expression was still preserved in the production code because it wasn't wrapped with `ngDevMode`. The observer is injected only in development mode. Additionally, we moved the logic from `ngOnDestroy` to avoid having an empty method in production.

PR Close #59481
2025-01-14 14:54:16 -05:00
arturovt
4491704fba refactor(common): drop enums by changing to const enum (#59468)
Note: this enums are not a part of the public API.

Prior to this commit, the compiler produced:

```js
var DateType;
(function (DateType) {
    DateType[DateType["FullYear"] = 0] = "FullYear";
    DateType[DateType["Month"] = 1] = "Month";
    DateType[DateType["Date"] = 2] = "Date";
    DateType[DateType["Hours"] = 3] = "Hours";
    DateType[DateType["Minutes"] = 4] = "Minutes";
    DateType[DateType["Seconds"] = 5] = "Seconds";
    DateType[DateType["FractionalSeconds"] = 6] = "FractionalSeconds";
    DateType[DateType["Day"] = 7] = "Day";
})(DateType || (DateType = {}));
```

With these changes, we allow objects to be dropped entirely and inlined.

PR Close #59468
2025-01-13 11:14:27 -05:00
arturovt
83bd63fa7c refactor(common): drop NullViewportScroller for client bundles (#59440)
In this commit, we replace the `isPlatformBrowser` runtime call with the `ngServerMode` in order to drop the `NullViewportScroller` for client bundles.

PR Close #59440
2025-01-09 12:33:04 -05:00
arturovt
dd1d69b2e2 refactor(common): drop PRELOADED_IMAGES name in production (#59425)
In this commit, we drop the `PRELOADED_IMAGES` injection token name in production.

PR Close #59425
2025-01-08 16:12:02 +00:00
Johnson Chu
a6cdbec09f refactor: remove unnecessary TSLint rule flags (#59365)
There are many TSLint rule flags in the source code that have no effect, and they can be safely removed to keep the code clean.

PR Close #59365
2025-01-07 16:06:21 +00:00
Jamie Rees
cb685d8571 refactor(common): update the NgOptimizedImage message to use @if instead of *ngIf (#59131)
This commit updates an error message to mention `@if` rather than the `*ngIf` directive.
PR Close #59131
2024-12-12 14:51:43 -08:00
Kristiyan Kostadinov
d010e11b73 feat(core): add event listener options to renderer (#59092)
Updates the `Renderer2.listen` signature to accept event options, as well as all adjacent types to it.

PR Close #59092
2024-12-10 13:39:47 -08:00
hawkgs
b8b6c8c77a refactor(docs-infra): convert code-example-s that have only region param to @example-s (#59004)
Replace all <code-example>-s within TS files that contain only a path and a region with JSDoc @example-s.

PR Close #59004
2024-12-04 18:05:59 +01:00
hawkgs
0513fbc9fc docs: set syntax highlighting of code examples MD code blocks (#59026)
Set the syntax highlighting based on the code examples' language.

PR Close #59026
2024-12-04 17:30:28 +01:00
Sheik Althaf
9658dd1fe3 refactor(common): remove standalone: true (#58949)
Removed the standalone true flag from common packages.

PR Close #58949
2024-12-04 12:41:51 +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
Kristiyan Kostadinov
e4c50b3bea feat(common): expose component instance in NgComponentOutlet (#58698)
Exposes the current instance of the component in the `NgComponentOutlet` directive.

PR Close #58698
2024-11-20 08:08:21 -08:00
Alan Agius
fee9db18a9 refactor: add @__PURE__ next to @pureOrBreakMyCode for improved bundler compatibility (#58297)
Added the `@__PURE__` annotation alongside `@pureOrBreakMyCode` to improve compatibility with third-party bundlers. This refactor follows optimization best practices, ensuring broader support across different tools, as `@pureOrBreakMyCode` was only supported by Closure Compiler.

PR Close #58297
2024-10-28 12:26:05 -07:00
Devashish Sarmah
24c6373820 feat(common): add optional rounded transform support in cloudinary image loader (#55364)
Currently, the cloudinary image loader doesn't support rounded transform.
Add a new prop called `rounded` to the existing `ImageLoaderConfig.loaderParams`

test(common): add test case for cloudinary loader rounded option

add test case for the rounded transform option of cloudinary loader

PR Close #55364
2024-10-23 07:59:13 -07:00
Sebastian Barfurth
13c13067bc feat(common): disable keyvalue sorting using null compareFn (#57487)
The keyvalue pipe sorts the entries of the input by key. This has been the subject of debate in the past (https://github.com/angular/angular/issues/42490). The core of the discussions is that it is often desirable (and perhaps expected) that they natural ordering of the input is respected. There are at least two workarounds to restore natural ordering, such as a `compareFn` that simply returns `1` or a custom pipe. However, both of these require code for pipe consumers to maintain or  copy around to many places.

Allowing `null` as `compareFn` and treating it as "natural order" is fairly simple to understand, backward compatible and was suggested a few times on https://github.com/angular/angular/issues/42490 where it seemed to be received well. Using `null` is also possible in templates without any component code changes.

PR Close #57487
2024-10-16 18:18:19 +00:00