Commit graph

315 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Alex Castle
50f08e6c4b feat(common): automatically use sizes auto in NgOptimizedImage (#57479)
Prepend 'auto' to value of the `sizes` prop generated by NgOptimizedImage, when image has a responsive srcset and is lazy-loaded.

PR Close #57479
2024-08-27 13:14:48 -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
Matthieu Riegler
2c4613a002 fix(common): Don't run preconnect assertion on the server. (#56213)
The `window` global is patched by domino on the server but the value of `window.location.href` isn't a valid base.

Before this change `getUrl()` would throw when running in devmode on the server.

Fixes #56207

PR Close #56213
2024-07-16 09:53:33 -07:00
Matthieu Riegler
d9fe17a3df refactor(common): Fire priority check on stable. (#56776)
To support routing on app init, the directive will now fire the priority check when the apps become stable.

fixes #56757

PR Close #56776
2024-07-03 14:40:47 +00:00
Matthieu Riegler
f407e3ce6f refactor(common): allow string urls in NgOptimizedImage input (#54901)
With this commit it is now possible to pass an url as placeholder for the image directive.

PR Close #54901
2024-07-01 18:13:24 +00:00
Andrew Kushnir
344775344b Revert "fix(common): Don't run preconnect assertion on the server. (#56213)" (#56740)
This reverts commit 39e48ce675.

PR Close #56740
2024-06-27 17:44:42 +00:00
Matthieu Riegler
39e48ce675 fix(common): Don't run preconnect assertion on the server. (#56213)
The `window` global is patched by domino on the server but the value of `window.location.href` isn't a valid base.

Before this change `getUrl()` would throw when running in devmode on the server.

Fixes #56207

PR Close #56213
2024-06-27 15:54:12 +00:00
Pawel Kozlowski
08f56d980b refactor(common): remove ng_switch ability to use == equality check (#56426)
In Angular v17 we've alligned NgSwitch equality check with the build in control
flow to be ===. At the same time we've left the ability to use ==. This ability was
controlled by the NG_SWITCH_USE_STRICT_EQUALS const targetted by the G3 patch.

This commits removes the infrastructure to swap equality operator in preparation
for the G3 patch removal.

PR Close #56426
2024-06-27 15:07:57 +00:00
Matthieu Riegler
cc4cb9608a refactor(common): Log a warning when the priority attribute of NgOptimizedImage is used too often. (#56669)
When the DOM content is loaded, Angular will log a warning message if the `priority` attribute is applied to often on `NgOptimizedImage` directive instances.

PR Close #56669
2024-06-26 12:43:00 -07:00
Matthieu Riegler
b2445a0953 fix(core): link errors to ADEV (#55554) (#56038)
Console error links will now point to adev.

PR Close #55554

PR Close #56038
2024-05-28 12:50:53 +02:00
Pawel Kozlowski
760207b254 Revert "fix(core): link errors to ADEV (#55554)" (#56031)
This reverts commit dd0700ff1d.
We will need G3 patch cleanup before this one can land.

PR Close #56031
2024-05-23 13:57:53 +02:00
Matthieu Riegler
dd0700ff1d fix(core): link errors to ADEV (#55554)
Console error links will now point to adev.

PR Close #55554
2024-05-23 11:58:54 +02:00
Matthieu Riegler
5926bf452d refactor(common): increment test coverage (#55532)
Ahead of #55283 and with what we learned from it,  let's improve our test coverage on the i18n subsystem.

PR Close #55532
2024-04-25 12:50:41 -07:00
Johnny Gérard
58e2f47426 test(common): update ImageKit low quality test (#55193)
For commit cd911a8008

PR Close #55193
2024-04-05 14:55:13 +00:00
Matthieu Riegler
ee3bb81f99 refactor(common): request low quality placeholder images (#54899)
For every built-in load, this commit adds a parameter to load low quality placeholder images. Using 20/100 as base value.

PR Close #54899
2024-03-25 11:17:33 -07:00
Kristiyan Kostadinov
219445cda4 fix(common): image placeholder not removed in OnPush component (#54515)
Fixes that the placeholder wasn't being removed when an optimized image is placed in an `OnPush` component.

Fixes #54478.

PR Close #54515
2024-02-20 09:49:58 -08:00
ascorbic
03c3b3eb79 feat(common): add Netlify image loader (#54311)
Add an image loader for Netlify Image CDN. It is slightly different in implementation from existing loaders, because it allows absolute URLs

Fixes #54303

PR Close #54311
2024-02-08 16:17:57 +00:00
Matthieu Riegler
122213d37d fix(common): The date pipe should return ISO format for week and week-year as intended in the unit test. (#53879)
ISO 8601 defines
* Monday as the first day of the week.
* week 01 is the week with the first Thursday

Therefore:
Sunday Dec 31st 2023 is the last day of the last week of the year : W52 2023.

PR Close #53879
2024-01-31 16:41:10 +00:00
Joey Perrott
0460a9dfaf refactor: migrate common to prettier formatting (#54150)
Migrate formatting to prettier for common from clang-format

PR Close #54150
2024-01-30 16:08:07 +00:00
Alex Castle
f5c520b836 feat(common): add placeholder to NgOptimizedImage (#53783)
Add a automatic placeholder implementation supporting loader-based and data URL placeholders

PR Close #53783
2024-01-29 16:00:38 +00:00
Andrew Scott
043b1ff8be refactor(common): Fix fake navigation to work with relative navigations (#53719)
This commit updates the implementation of the fake navigation to support
relative navigation requests.

PR Close #53719
2024-01-03 10:16:57 -08:00
Thomas Wilkinson
27f5eed017 refactor(common): Add fake implementation of PlatformNavigation. (#52363)
This implementation does most, but not all, of the things the native
Navigation API does. Also adds a spec that tests all the currently
supported behaviors.

PR Close #52363
2023-11-09 18:01:33 +00:00
Alex Castle
f86fb8eb03 fix(common): apply fixed_srcset_width value only to fixed srcsets (#52459)
add logic to NgOptimizedImage to keep fixed_srcset_width from applying to large responsive images, which is incorrect behavior

PR Close #52459
2023-10-31 14:57:19 -07:00
Kristiyan Kostadinov
c07805612f test(core): clean up unnecessary nesting in old tests (#52239)
A lot of our tests are wrapped in `{}` which serves no purpose, aside from increasing the nesting level and, in some cases, causing confusion. The braces appear to be a leftover from a time when all tests were wrapped in a `function main() {}`. The function declaration was removed in #21053, but the braces remained, presumably because it was easier to search&replace for `function main()`, but not to remove the braces at the same time.

PR Close #52239
2023-10-19 09:26:15 -07:00
cexbrayat
b1cb0b395b fix(common): missing space in ngSwitch equality warning (#52180)
This adds a missing space between the sentences of the `===` vs `==` ngSwitch warning.

PR Close #52180
2023-10-12 15:44:46 +02:00
Pawel Kozlowski
28a5925f53 fix(common): use === operator to match NgSwitch cases (#51504)
This change adjust the equality comparator used by NgSwitch - now it
defaults to === from previously used ==. This change is based on the
following reasoning:
- align behaviour with the built-in switch block);
- improve performance (avoid type coercion);
- enable better type-checking.

BREAKING CHANGE:

the NgSwitch directive now defaults to the === equality operator,
migrating from the previously used ==. NgSwitch expressions and / or
individual condition values need adjusting to this stricter equality
check. The added warning message should help pinpointing NgSwitch
usages where adjustements are needed.

Fixes #33873

PR Close #51504
2023-10-09 10:10:21 -07:00
Alex Castle
048f400efc feat(core): add warnings for oversized images and lazy-lcp (#51846)
Add warnings for two image-related performance problems that apply beyond just apps using NgOptimizedImage.

PR Close #51846
2023-10-06 12:14:32 -07:00
Paul Gschwendtner
7426948ff6 refactor(common): update NgTemplateOutlet to no longer rely on context swapping (#51887)
The context of an embedded view ref at some point was switched from a
getter to an actual assignable property. This is something we reverted
with the previous commit as it introduces additional complexity for our
generated code (in terms of closures capturing the `ctx`).

This change impacted the template outlet code because we actively relied
on swapping out the full context if the user changes it. Previousl,
before we allowed to swap out the context (in v16), we mutated the
initial view context if it didn't change structurally- and in other
cases the view was re-created. We improved this performance aspect with
the changes to allow for the context to be swapped out + actually also
fixed a bug where the initial context object was mutated and the user
could observe this change.

This commit adjusts for context not being replacable- while still
keeping the bugs fixed and preserving the performance wins of not
having to destroy/re-create the view whenever the context changes.

Benchmarks: https://hackmd.io/J0Ci_JzxQ0K1AA1omXhIQQ

PR Close #51887
2023-10-04 08:14:35 -07:00
Kristiyan Kostadinov
52cc7f839b build: align with internal tsconfig options (#51728)
Currently internally Angular has some customized tsconfig files, because we don't align with the tsconfig of the rest of g3. These changes enable `noImplicitReturns` and `noPropertyAccessFromIndexSignature` to align better with the internal config.

PR Close #51728
2023-09-12 11:39:42 -07:00
Alex Castle
d910bf8a84 fix(common): Allow safeUrl for ngSrc in NgOptimizedImage (#51351)
Allow safeUrl and add transformer to immediately convert ngSrc to string

PR Close #51351
2023-08-17 10:20:35 -07:00
hyperlife1119
29d358170b feat(common): add component input binding support for NgComponentOutlet (#51148)
This commit add component input binding support for NgComponentOutlet.

PR Close #51148
2023-07-25 09:16:19 -07:00
Alex Castle
1837efb9da feat(common): Allow ngSrc to be changed post-init (#50683)
Remove thrown error when ngSrc is modified after an NgOptimizedImage image is initialized

PR Close #50683
2023-07-11 08:30:49 -07:00
Matthieu Riegler
ad28cddd41 refactor(platform-browser): replace our own toBeAnInstanceOf with toBeInstanceOf (#50661)
There is no need to maintain that matcher since jasmine provides its own !

PR Close #50661
2023-06-14 10:58:04 +02:00
Andrew Kushnir
cefa3de3de refactor(common): use transform functions in NgOptimizedImage inputs (#50580)
This commit refactors the code of NgOptimizedImage directive to switch from getter/setter approach to convers inputs to use the `transform` function instead.

PR Close #50580
2023-06-13 13:20:49 +02:00
Alex Rickabaugh
55d6147d29 Revert "feat(common): add component input binding support for NgComponentOutlet (#49735)"
This reverts commit f3867597f0. This PR has
property renaming bugs in g3.
2023-06-08 10:32:49 -07:00
hyperlife1119
f3867597f0 feat(common): add component input binding support for NgComponentOutlet (#49735)
This commit add component input binding support for NgComponentOutlet.

PR Close #49735
2023-06-08 10:00:34 -07:00
Alex Rickabaugh
72b4ff4b9e fix(common): untrack subscription and unsubscription in async pipe (#50522)
This commit wraps the actual subscription/unsubscription in the `async`
pipe with `untracked`, to ensure that any signal reads/writes which might
take place in `Observable` side effects are not attributed to the template.

Fixes #50382

PR Close #50522
2023-05-31 12:38:30 -07:00
Matthieu Riegler
f305f224bd refactor(common): add missing override to satisfy the linter (#49599)
Linter was complaining of missing `override` despite being OK on the CI. this commits add them.

PR Close #49599
2023-03-28 10:12:36 -07:00
Tano Abeleyra
6499f5ae28 fix(common): invalid ImageKit transformation (#49201)
q-auto is an invalid/unsupported transformation and should not be used

PR Close #49201
2023-03-27 08:33:22 -07:00
Alan Agius
67743340a7 test(common): update async pipe tests to fix test errors (#49433)
The below error is displayed during some tests

```js
ERROR: 'Unhandled Promise rejection:', 'Cannot read properties of null (reading 'markForCheck')', '; Zone:', 'ProxyZone', '; Task:', 'Promise.then', '; Value:', TypeError: Cannot read properties of null (reading 'markForCheck')
TypeError: Cannot read properties of null (reading 'markForCheck')
    at AsyncPipe2._updateLatestValue (http://angular-ci.local:9876/base/dist/legacy-test-bundle.spec.js?49174f830d8743d5c8a9551b77550b859b934291:51947:19)
```

This is caused by the fact that `ref` in `AsyncPipe` is initialized with a value of `null` which causes `_updateLatestValue` to fail since it is not expected to be `null`.

This change ensures that a `ref` is always provided and that all subscriptions are disposed off after each test.

PR Close #49433
2023-03-15 17:19:37 -07:00