Commit graph

11599 commits

Author SHA1 Message Date
Andrew Scott
3839cfbb18 fix(router): Routed components never inherit RouterOutlet EnvironmentInjector (#54265)
This commit ensures components in the route config predictably always
get their providers from the hierarchy available to routes rather than
sometimes being dependent on where they are inserted.

fixes #53369

BREAKING CHANGE: Providers available to the routed components always
come from the injector heirarchy of the routes and never inherit from
the `RouterOutlet`. This means that providers available only to the
component that defines the `RouterOutlet` will no longer be available to
route components in any circumstances. This was already the case
whenever routes defined providers, either through lazy loading an
`NgModule` or through explicit `providers` on the route config.

PR Close #54265
2024-04-01 09:19:13 -07:00
Andrew Scott
87f3f27f90 feat(router): Allow resolvers to return RedirectCommand (#54556)
Returning a `RedirectCommand` from a resolver can be interpreted as
distinctly different from regular resolved data. When a resolver returns
`RedirectCommand` we can interperet this as an intention to redirect in
the same way as other guards.

resolves #29089

PR Close #54556
2024-03-30 10:52:44 -07:00
Andrew Scott
7d4dd08591 test(core): Update hybrid mode scheduling test to wait for fixture stable (#55076)
Now that pending tasks contribute to fixture stability, the tests can be
simplified.

PR Close #55076
2024-03-29 16:37:43 -07:00
Kristiyan Kostadinov
0c20c4075a fix(migrations): avoid conflicts with some greek letters in control flow migration (#55113)
The control flow migration was using a couple of Greek letters as placeholders. This ended up conflicting with templates authored in Greek.

These changes use a more obscure placeholder to make conflicts less likely. It also moves the placeholder generation to a centralized function so it's easier to make changes if we decide to update the pattern again.

Fixes #55085.

PR Close #55113
2024-03-29 13:10:52 -07:00
Johnny Gérard
50da50103f docs(common): clean up comment (#55088)
PR Close #55088
2024-03-29 13:02:44 -07:00
Angular Robot
418b7dff4b build: lock file maintenance (#55022)
See associated pull request for more information.

PR Close #55022
2024-03-29 12:59:32 -07:00
Andrew Scott
38bb95a8f5 Revert "refactor(compiler): add support for the new search element (#54945)" (#55127)
This reverts commit 367b3ee6e9.
The search element is not a void element but existing components may use
the same selector and be used as a void element.

PR Close #55127
2024-03-29 12:56:31 -07:00
Andrew Scott
3974c2184e refactor(core): All views attached to application are treated as OnPush in zoneless (#55099)
This change treats all views attached to `ApplicationRef` as `OnPush`,
meaning that they have to be explicitly marked for check in order to be
refreshed when a tick happens. This prevents "accidentally" refreshing
views which have `Default` change detection as a side effect of running
change detection from an unrelated notification.

In addition, this change helps us achieve one of the big goals of the
project: that we can provide a testing experience which gives developers
more confidence that a component is zoneless-compatible. Because
`ComponentFixture` change detection is run through `ApplicationRef`
instead of `ChangeDetectorRef` when zoneless is enabled, this ensures
that the component under test has correctly been marked for check in
order to be updated. Without this, calling
`ComponentFixture.detectChanges` would allow a test to _force_ change
detection on a view when Angular would have otherwise not known that it
needed to be updated. Calling `ComponentFixture.detectChanges` on a component
which is not marked for check will now omit refreshing component view.

PR Close #55099
2024-03-29 10:42:21 -07:00
Matthieu Riegler
367b3ee6e9 refactor(compiler): add support for the new search element (#54945)
See #whatwg/html#5811
Spec: https://html.spec.whatwg.org/multipage/grouping-content.html#the-search-element

fixes #54944

PR Close #54945
2024-03-29 10:01:54 -07:00
Andrew Scott
a99cb7ce5b fix(core): zoneless scheduler should check if Zone is defined before accessing it (#55118)
zoneless scheduler should check if Zone is defined before accessing it

fixes #55116

PR Close #55118
2024-03-29 09:59:00 -07:00
Angular Robot
218c5bd2b3 build: update dependency @babel/core to v7.24.3 (#55038)
See associated pull request for more information.

PR Close #55038
2024-03-29 09:44:58 -07:00
Gerald Monaco
a5fa279b6e fix(core): prevent i18n hydration from cleaning projected nodes (#54823)
Rework the i18n cleanup behavior to more closely match that of containers. Specifically, we assume that nodes are going to be claimed unless they are part of a branching ICU block.

During hydration, we then track which ICU case was active at serialization time, and which was active during hydration. Any remaining cases that weren't used during hydration are then cleaned up.

PR Close #54823
2024-03-29 09:35:43 -07:00
Gerald Monaco
f44a5e4604 fix(core): support content projection and VCRs in i18n (#54823)
Modifies the i18n pre-hydration logic to correctly support content projection and elements that act as view containers.

PR Close #54823
2024-03-29 09:35:43 -07:00
Gerald Monaco
146306a141 feat(core): add support for i18n hydration (#54823)
Add support for hydrating i18n blocks. This is accomplished by serializing information about selected ICU cases for a block during server-side rendering.

During hydration, this data is read and is used to traverse both an AST of the translated message and the DOM, in parallel, to map each LView with an RNode.

Finally, this mapping is used while nodes are being created (either via i18n or their respective instructions) to locate existing nodes.

PR Close #54823
2024-03-29 09:35:43 -07:00
Andrew Scott
860de662b6 refactor(router): Navigation promise should resolve false instead of null on skip (#55068)
This commit updates the internal resolve value of the navigation promise
to use `false` instead of `null` when a navigation is skipped. The
navigation promise type requires `boolean` so the correct resolution to
match the truthy/falsiness of the currently resolved value, `null`, is
`false` instead.

PR Close #55068
2024-03-29 09:16:47 -07:00
Andrew Scott
2794084d74 refactor(router): move navigation error handler call to location of error emit (#55068)
This commit moves the call to the error handler to the location where
the error event emits instead of having it indirectly work through the
events subscription. This change would also allow the handler to return
a value which can be handled by the navigation transition.

PR Close #55068
2024-03-29 09:16:47 -07:00
Andrew Scott
17369ed1e9 refactor(router): Correct resolve value for error handler case (#55068)
This commit fixes the types on the error handler resolve and reject
functions and also ensures that the resolve value matches the API type
(`boolean`, not "any random value returned from `errorHandler`"). This
could be considered a breaking change but I would argue instead that
relying on the return value of the error handler is API misuse because
the promise returned by the router navigation _does not_ include `any`
in its type.

PR Close #55068
2024-03-29 09:16:46 -07:00
Andrew Scott
4073d3854f refactor(router): fix internal types of resolve and reject promises (#55068)
This commit fixes the internal types for the resolve and reject
functions used for the router navigation Promise. These are currently
typed as `any`.

PR Close #55068
2024-03-29 09:16:46 -07:00
Andrew Scott
0b450ffa6f refactor(core): Move private export testing file to src (#55103)
This matches the private export approach for files in other packages.

PR Close #55103
2024-03-28 16:35:25 -07:00
Andrew Scott
ac0a51ce3d refactor(core): Update SchedulingMode to be regular enum (#55103)
Angular recently gained a local compilation mode (see commit 345dd6d).
This is intended to be used with the TypeScript compiler option isolatedModules, which bans imports of const enums.

PR Close #55103
2024-03-28 16:35:24 -07:00
Andrew Scott
ea2d42507e refactor(core): Remove unused change detection flags (#55057)
This commit removes unused change detection flags.

PR Close #55057
2024-03-28 15:47:41 -07:00
Andrew Scott
22dd52f460 refactor(core): re-export private exports from testing (#55101)
This commit re-exports private exports  from testing package.

PR Close #55101
2024-03-28 13:54:16 -07:00
Andrew Scott
f9417ea3a8 refactor(core): Privately export SchedulingMode enum (#55100)
Expose enum for early testers so they don't have to awkwardly put `0`
for Hybrid mode.

PR Close #55100
2024-03-28 13:15:03 -07:00
Andrew Scott
edfc5a9c3b refactor(core): private export token to disable fixture.detectChanges error (#55098)
While we do want to discourage `fixture.detectChanges`, it is yet to be
determined how this should be accomplished (warning, documentation, etc.). At
the moment, not being able to disable the error at all is entirely
prohibitive for existing test suites to use zoneless change detection in
tests. We would much rather allow existing test suites to disable the
error and use the zoneless change detection than prevent them from using
it entirely until all the `detectChanges` calls have been fixed.
Calling `detectChanges` manually can hide errors related to change
detection timing, but it is even worse when the "PseudoApplication"
fixture used (since it runs change detection _only_ on the component
rather than through `ApplicationRef`).

PR Close #55098
2024-03-28 13:14:27 -07:00
Garrett Darnell
b87b2fc05c docs(core): fix toSignal docs (#54964)
PR Close #54964
2024-03-28 13:06:43 -07:00
Matthieu Riegler
f523415203 docs: drop glossary links (#55044)
PR Close #55044
2024-03-28 13:02:50 -07:00
Andrew Scott
914e4530b0 fix(core): test cleanup should not throw if Zone is not present (#55096)
The test hooks should not throw if applications choose not to load ZoneJS.

fixes #48198

PR Close #55096
2024-03-28 12:12:30 -07:00
Charles Lyding
a48afe0d94 fix(language-service): avoid generating TS syntactic diagnostics for templates (#55091)
Angular's template files are not valid TypeScript. Attempting to get syntactic
diagnostics from the underlying TypeScript language service will result in
a large amount of false positive errors. Only actual TypeScript files should
be analyzed by the underlying TypeScript language service for syntactic errors.

PR Close #55091
2024-03-28 12:10:40 -07:00
JiaLiPassion
ddbf6bb038 fix(zone.js): make sure fakeasync use the same id pool with native (#54600)
Close #54323

fakeAsync should use the same timerId pool with native, so they will not
conflict.

PR Close #54600
2024-03-28 10:30:25 -07:00
Kristiyan Kostadinov
63688714ae fix(migrations): account for variables in imports initializer (#55081)
Fixes that the control flow migration was throwing an error if the `imports` of a component are initialized to an identifier.

Fixes #55080.

PR Close #55081
2024-03-28 09:40:31 -07:00
Andrew Kushnir
86a359b399 fix(core): establish proper injector resolution order for @defer blocks (#55079)
This commit updates the `@defer` logic to establish proper injector resolution order. More specifically:

- Makes node injectors to be inspected first, similar to how it happens when `@defer` block is not used.
- Adds extra handling for the Router's `OutletInjector`, until we replace it with an `EnvironmentInjector`.

Resolves #54864.
Resolves #55028.
Resolves #55036.

PR Close #55079
2024-03-28 09:23:38 -07:00
Kristiyan Kostadinov
336916ceb0 refactor(compiler-cli): allow source file validator rule to produce a single diagnostic (#54993)
Allows for `SourceFileValidatorRule.checkNode` to produce a single diagnostic. The most common case should be one diagnostic per node so this allows us to save some array allocations.

PR Close #54993
2024-03-28 09:17:04 -07:00
Kristiyan Kostadinov
694ba79cbf fix(compiler-cli): report cases where initializer APIs are used in a non-directive class (#54993)
Expands the check for initializer APIs to also flag when the function is called on a class that isn't a component or directive.

PR Close #54993
2024-03-28 09:17:03 -07:00
Kristiyan Kostadinov
78188e877a fix(compiler-cli): add diagnostic if initializer API is used outside of an initializer (#54993)
Adds a rule that will produce a diagnostic when an initializer-based API is used outside of an initializer.

Fixes #54381.

PR Close #54993
2024-03-28 09:17:02 -07:00
Kristiyan Kostadinov
8226be6abf refactor(compiler-cli): introduce infrastructure for running additional checks against TypeScript files (#54993)
Adds the new `SourceFileValidator` that will be used to check for file-level issues that may prevent Angular from working, like invoking the `input()` function outside of an initializer. Currently only one check is planned, but this setup will allow us to easily add more in the future.

PR Close #54993
2024-03-28 09:17:01 -07:00
Kristiyan Kostadinov
3d9f01c6ec refactor(compiler-cli): add API to check if imports exist (#54993)
Adds a couple of APIs to the `ImportedSymbolsTracker` that allow us to quickly check if a specific symbol is imported in a file.

PR Close #54993
2024-03-28 09:17:00 -07:00
Andrew Scott
e02bcf89cf fix(core): Fix clearing of pending task in zoneless cleanup implementation (#55074)
This commit fixes a mistake in #54952 where the first pending task was falsey because its ID is 0

PR Close #55074
2024-03-27 14:29:08 -07:00
Andrew Scott
80f96e7c51 refactor(core): Provide scheduler for use and coordination with zone change detection (#54952)
This commit makes the zoneless scheduler (privately) available to applications that
have ZoneJS-based change detection. This would catch any changes of
interest (signal updates, `markForCheck` calls, attaching `Dirty` views)
that happen outside the Angular Zone.

See #53844 for additional information about why this is important.
More details to come in the a future commit that makes this a public option.

PR Close #54952
2024-03-27 11:36:56 -07:00
Andrew Scott
658cf8c384 fix(core): ComponentFixture stability should match ApplicationRef (#54949)
This change aligns the stability of `ComponentFixture` with that of
`ApplicationRef`, preventing confusing differences between the two as
more APIs start using the `PendingTasks` that may not be tracked by
`NgZone`.

BREAKING CHANGE: `ComponentFixture.whenStable` now matches the
`ApplicationRef.isStable` observable. Prior to this change, stability
of the fixture did not include everything that was considered in
`ApplicationRef`. `whenStable` of the fixture will now include unfinished
router navigations and unfinished `HttpClient` requests. This will cause
tests that `await` the `whenStable` promise to time out when there are
incomplete requests. To fix this, remove the `whenStable`,
instead wait for another condition, or ensure `HttpTestingController`
mocks responses for all requests. Try adding `HttpTestingController.verify()`
before your `await fixture.whenStable` to identify the open requests.
Also, make sure your tests wait for the stability promise. We found many
examples of tests that did not, meaning the expectations did not execute
within the test body.

In addition, `ComponentFixture.isStable` would synchronously switch to
true in some scenarios but will now always be asynchronous.

PR Close #54949
2024-03-27 11:01:28 -07:00
David Calawa
60f1d681e0 fix(router): preserve replaceUrl when returning a urlTree from CanActivate (#54042)
This commit will fix the issue of the setting of NavigationExtras.replaceUrl being lost when
returning a urlTree from a CanActivateFn.

Fixes #53503

BREAKING CHANGE: When a a guard returns a `UrlTree` as a redirect, the
redirecting navigation will now use `replaceUrl` if the initial
navigation was also using the `replaceUrl` option. If this is not
desirable, the redirect can configure new `NavigationBehaviorOptions` by
returning a `RedirectCommand` with the desired options instead of `UrlTree`.

PR Close #54042
2024-03-27 10:57:52 -07:00
Andrea Canciani
f3b624553a refactor: fix a number of typos throughout the codebase (#55018)
Fix some typos detected using spellchecking tools, both in
documentation and in code (comments, identifiers).

PR Close #55018
2024-03-27 10:54:31 -07:00
Matthieu Riegler
b230bbc90d refactor(compiler): Do not extract internal methods. (#54850)
internal methods are not exposed to end users and should not be extracted.

PR Close #54850
2024-03-27 10:48:05 -07:00
JiaLiPassion
e44b077cbd fix(zone.js): should not clear onhandler when remove capture listener (#54602)
Close #54581

Should not clear `onHandler` when remove capture event listeners.

PR Close #54602
2024-03-27 10:40:05 -07:00
Andrew Scott
eae75ff3f9 fix(router): RouterLinkActive will always remove active classes when links are not active (#54982)
Previously, `RouterLinkActive` would only add or remove the active classes when
its active state changed. This means that if you accidentally add one of
the active classes to the static class attribute, it won't get removed
until the link becomes active and then deactives (because the class is
added at creation time and never removed until the `RouterLinkActive`
state changes from active to inactive).

fixes #54978

PR Close #54982
2024-03-27 10:16:16 -07:00
Charles Lyding
f2a98cdce0 refactor(language-service): use native Array flatMap (#55011)
The custom flatMap implementation can now be removed as Array contains a
native implementation that is available for all supported Node.js versions.

PR Close #55011
2024-03-27 10:15:34 -07:00
Charles Lyding
4166dfc1b6 fix(language-service): prevent underlying TS Service from handling template files (#55003)
When the `angularOnly` option is disabled, the underlying TypeScript language service
was previously used for all files including `.html` template files. This can result in
incorrect responses including a large amount of invalid diagnostics for a template file.
Checks have now been added to only use the Angular Language service for template files
which can properly handle template files. Additionally, the check for a TypeScript file
name has now been expanded to encompass all current file extension forms.

PR Close #55003
2024-03-27 09:57:31 -07:00
Paul Gschwendtner
03b1ac3ce7 refactor(compiler-cli): improve error message for uncaught FatalDiagnosticError (#54981)
For `FatalDiagnosticError` we are currently hiding the `message` string
field in favor of the actual TS `diagnosticMessage`.

This works as expected, but makes these errors hard to debug in certain
environments (e.g. Jasmine). That is because `null` is the value of
`message` at runtime. We fix this by just overriding the type, like we
originally intended to do.

In addition, we properly render message chains in the `Error#message`
field— so that these errors, when uncaught, are somewhat reasonable and
can be useful.

PR Close #54981
2024-03-27 09:54:46 -07:00
Paul Gschwendtner
6219341d26 fix(compiler-cli): report errors when initializer APIs are used on private fields (#54981)
This commit ensures that the new APIs like `input`, `model`, `output`,
or signal-based queries are not accidentally used on fields that have a
problematic visibility/access level that won't work.

For example, queries defined using a private identifier (e.g. `#bla`)
will not be accessible by the Angular runtime and therefore _dont_ work.

This commit ensures:

- `input` is only declared via public and protected fields.
- `output` is only declared via public and protected fields.
- `model` is only declared via public and protected fields.
- signal queries are only declared via public, protected and TS private
  fields (`private` works, while `#bla` does not).

Fixes #54863.

PR Close #54981
2024-03-27 09:54:45 -07:00
Paul Gschwendtner
64ae07766e refactor(compiler-cli): support enforcing field access for initializer APIs (#54981)
An initializer API like `input`, `output`, or signal queries may not be
compatible with certain access levels. E.g. queries cannot work with ES
private class fields.

This commit introduces a check for access levels into the initializer
API recognition— enforcing that every initializer API *clearly*
specifies what type of access is allowed.

PR Close #54981
2024-03-27 09:54:45 -07:00
Paul Gschwendtner
9366a94781 refactor(compiler-cli): reflection should inspect ES private fields and visibility (#54981)
This commit changes the TypeScript reflection host to:

* inspect / process ES private fields. e.g. `#someField` — those are
  ignored right now and we would want to check them to issue
  diagnostics.

* determine an access level of a class member. E.g. a member may be
  public, may be private, may be ES private, or public readonly. This
  can then be used in various checks later.

PR Close #54981
2024-03-27 09:54:45 -07:00