Commit graph

4587 commits

Author SHA1 Message Date
Andrew Scott
0147e0b85a fix(core): exhaustive checkNoChanges should only do a single pass (#55839)
Because exhaustive checks traverse the whole tree regardless of the
dirty state, it breaks some expectations around how change detection
should be running. When a view has transplanted views, it
unconditionally marks all ancestors for traversal, assuming this is fine
because the loop will just traverse them and find nothing dirty.
However, exhaustive checkNoChanages actually refreshes everything during
traversal.

This update ensures the exhaustive check only does a single pass and
also prevents some unnecessary marking of transplanted views for
refresh since we know they're going to be reached.

PR Close #55839
2024-05-17 12:24:36 -07:00
Matthieu Riegler
0e16654be4 refactor(forms): remove deprecated symbols (#55723)
Follow-up of #55698 to help remove the symbols from G3.

PR Close #55723
2024-05-17 10:12:08 -07:00
cexbrayat
69085ea26e fix(core): error about provideExperimentalCheckNoChangesForDebug uses wrong name (#55824)
The error about `provideExperimentalCheckNoChangesForDebug` mentions `provideCheckNoChangesForDebug` instead.

PR Close #55824
2024-05-16 09:02:29 -07:00
Andrew Scott
e76bebd409 refactor(core): Update error for both zone and zoneless to be only for apps (#55813)
Developers may want to enable zoneless for all tests by default by
adding the zoneless provider to `initTestEnvironment` and then
temporarily disabling it for individual tests with the zone provider
until they can be made zoneless compatible.

PR Close #55813
2024-05-15 13:27:27 -07:00
Andrew Scott
eda86d5347 refactor(core): calling autoDetectChanges without params works for zoneless (#55800)
This was mistakenly implemented automatically by the override without
filling in the default value of `true` like it is for the zone-based
fixture.

PR Close #55800
2024-05-15 08:46:30 -07:00
cexbrayat
c4b2f18709 fix(migrations): migrate HttpClientTestingModule in test modules (#55803)
The migration was breaking tests with test modules that imported `HttpClientTestingModule`,
as it removed the JS imports without migrating the module imports.

The migration now handles the case where `HttpClientTestingModule` is used in test modules,
by replacing the module import with the `provideHttpClient` and `provideHttpClientTesting` providers.

Before:
```ts
import { HttpClientTestingModule } from '@angular/common/http/testing';

@NgModule({
  declarations: [AppComponent],
  imports: [HttpClientTestingModule],
})
export class TestModule {}
```

After:
```ts
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';

@NgModule({
  declarations: [AppComponent],
  imports: [],
  providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
})
export class TestModule {}
```

PR Close #55803
2024-05-15 08:45:31 -07:00
Tom Wilkinson
43525988b8 refactor(core): Add an ActionResolver option to Dispatcher. (#55757)
This will enable internal usages to migrate from ActionResolver in
EventContrat to ActionResolver in Dispatcher.

PR Close #55757
2024-05-14 15:16:26 -07:00
Tom Wilkinson
3b1b4e20c1 refactor(core): Move preventDefault to Dispatcher (#55756)
This is a simple move.

PR Close #55756
2024-05-14 14:35:00 -07:00
Alex Rickabaugh
1fd63e9cff refactor(core): deprecate @Component.interpolation (#55778)
Angular has long had the ability to use different interpolation delimiters
(by default `{{` and `}}`). This concept was copied over from AngularJS,
where AngularJS syntax is included in HTML sent over the network to the
browser. Occasionally developers would use SSR frameworks which _also_ have
interpolation syntaxes of their own, so there was a need to change the
delimiters used by AngularJS to avoid conflicts.

Since Angular templates are always processed by our compiler and the
interpolation characters are never processed by other systems first, this
option is vestigial in Angular and only increases the complexity of our
parser.

DEPRECATED: `@Component.interpolation` is deprecated. Use Angular's
delimiters instead.

PR Close #55778
2024-05-14 11:48:12 -07:00
cexbrayat
bb4a4016a9 fix(migrations): preserve existing properties in HttpClientModule migration (#55777)
The `HttpClientModule` migration was dropping the existing properties other than imports and providers when updating an `@NgModule`, `@Component` or `configureTestingModule`.

PR Close #55777
2024-05-14 11:10:57 -07:00
Thomas Nguyen
bfb5f2ba59 refactor(core): Simplify event handler extraction logic. (#55747)
This reuses information already recorded during hydration to
remove jsaction attributes to also stash event handlers. This avoids
a tree walk and looku.

PR Close #55747
2024-05-14 09:38:43 -07:00
Thomas Nguyen
89e860cc30 refactor(core): Add four tests and fix code to make tests pass. (#55747)
The first test asserts that bubbling does not work right now.

The second asserts that stopPropagation works, which should pass when test #1 passes too.

The third test asserts properties about the events passed to the event handler.

THe fourth test asserts that mouse events do not translate to jsaction nor help emit the jsaction binary. This required a change in code to make this pass.

PR Close #55747
2024-05-14 09:38:43 -07:00
Alan Agius
9d1acd6e92 build: switch from rollup and terser to esbuild for creating contract bundle (#55705)
This commit implements the replacement of rollup and terser with esbuild for generating the contract_bundle binary. The transition is facilitated by optimizations aimed at reducing the bundle size.

PR Close #55705
2024-05-13 12:49:30 -07:00
Tom Wilkinson
dc0c55c930 refactor(core): Rename BaseDispatcher to Dispatcher. (#55721)
Rename `BaseDispatcher` to `Dispatcher` and `Dispatcher` to
`LegacyDispatcher`. The `GlobalHandler` type and `stopPropagation`
function needs to be left for now in dispatcher.ts as it was not
exported previously from legacy_dispatcher.ts.

PR Close #55721
2024-05-13 12:30:10 -07:00
Matthieu Riegler
5f3742de6c refactor(forms): deprecate unwanted control events aliases (#55698)
This commit deprecates the aliases for the control events to ease the changes in G3
A follow-up commit will remove those deprecated entries.

PR Close #55698
2024-05-13 11:16:15 -07:00
Kristiyan Kostadinov
6906ff0131 refactor(core): clean up clang comments and workarounds (#55750)
Since we aren't using clang anymore, we can remove the comments and the workarounds that were in place to prevent it from doing the wrong thing.

PR Close #55750
2024-05-13 11:10:36 -07:00
Tom Wilkinson
eb31f2c775 refactor(core): Remove custom event and replay behavior. (#55695)
These behaviors have been moved back to g3.

PR Close #55695
2024-05-13 09:36:04 -07:00
iteriani
7c9d37d798 refactor(core): Remove enums from event-dispatch. (#55421)
These cause optimization issues in external.

PR Close #55421
2024-05-13 09:12:45 -07:00
iteriani
72b107b2a7 refactor(core): Use early event contract instead of the event contract in bootstrap. (#55587)
This also fixes an existing bug where we erase the jsaction attribute too early.

Now the event contract binary is 608 bytes :D.

PR Close #55587
2024-05-09 14:34:10 -07:00
Thomas Nguyen
d00f9e85bb refactor(core): Export some more symbols and check for truthiness on event types before adding them. (#55587)
In some cases, we will be passing in undefined for capture events, so handle this.

PR Close #55587
2024-05-09 14:34:10 -07:00
Matthieu Riegler
61007dced0 fix(forms): Add event for forms submitted & reset (#55667)
This commit adds 2 new events to the unified control event observable.

PR Close #55667
2024-05-09 09:21:15 -07:00
Alan Agius
f9aac834f5 refactor(core): a couple of minor changes to the early-event-contract (#55704)
This changes include
- Using multi line comments to write JSDoc comments which improves DX
- Use `this.container` instead of `window.document.documentElement`

PR Close #55704
2024-05-08 14:00:30 -07:00
Andrew Scott
6b97aec621 refactor(core): feature for potential zoneless-compatibility debug check (#55663)
This commit adds a feature that is useful for determining if an
application is zoneless-ready. The way this works is generally only
useful right now when zoneless is enabled. Some version of this may be useful in
the future as a general configuration option to change detection to make
`checkNoChanges` pass always exhaustive as an opt-in to address #45612.

Because this is an experimental, debug-only feature, it is okay to merge
during the RC period.

PR Close #55663
2024-05-07 13:39:14 -07:00
Andrew Scott
9eb7478e5d refactor(core): Throw a runtime error if both zone and zoneless are provided (#55410)
This commit adds a dev-mode error if both the zone and zoneless
providers are used together.

PR Close #55410
2024-05-07 13:37:43 -07:00
Tom Wilkinson
1b631ae52e refactor(core): Move global dispatch behavior into Dispatcher. (#55692)
This behavior is now implemented by calling `dispatch` whether or not
the `action` is populated. The `Dispatcher` then does global dispatch
and early returns if there's no action.

PR Close #55692
2024-05-07 12:00:40 -07:00
Thomas Nguyen
bdd6d3c4d8 refactor(core): Fix timing of removal of jsaction attribute to be after event replay. (#55696)
This otherwise leads to bugs where, by the time replay needs the attribute, hydration
happens and it's gone.

PR Close #55696
2024-05-07 08:16:17 -07:00
Andrew Scott
b721e5d9c8 refactor(core): private export token that indicates if zone scheduling is provided (#55690)
This is needed internally to determine whether to provide zone or
zoneless by default.

PR Close #55690
2024-05-06 16:01:49 -07:00
Rahat Ahmed
8483721f32 refactor(core): Remove unused JSNAMESPACE_SUPPORT from event-dispatch (#55619)
The usage of this option has been removed from google3 code, so we don't
need to keep it around anymore.

PR Close #55619
2024-05-06 14:58:26 -07:00
Andrew Scott
0510930a25 fix(core): TestBed should not override NgZone from initTestEnvironment (#55226)
Prior to this change, `NgZone` was provided by default in TestBed in a
location that would override anything configured in
`TestBed.initTestEnvironment`. This change moves the default `NgZone`
provider to the `RootScopeModule` and these providers can be overridden
by the ones in `additionalModuleTypes`, which are assigned from the
first argument of `initTestEnvironment`. This makes it possible to
configure Zone globally for all tests as opposed to needing to repeat it
in `configureTestingModule` of each suite.

PR Close #55226
2024-05-06 13:33:17 -07:00
cexbrayat
8459ee46cb fix(migrations): handle more cases in HttpClientModule migration (#55640)
This commit handles two cases that were breaking applications when using the new migration:

- tests using `HttpClientModule` in `TestBed.configureTestingModule` were broken as the import was removed, but the module is still present in the test configuration. It now properly adds `provideHttpClient(withInterceptorsFromDi())` and related imports to the test.
- tests using `HttpClientTestingModule` were migrated to use `provideHttpClient(withInterceptorsFromDi())` but the necessary imports were not added. They are now added by the migration.

PR Close #55640
2024-05-06 12:29:18 -07:00
iteriani
6baa3bcc57 refactor(core): Allow the container and the listenable element to be configurable for early event contract. (#55586)
This will allow a multi-app application to listen to early events from different elements and place them
on a separate field on the window.

PR Close #55586
2024-05-06 08:15:54 -07:00
Matthieu Riegler
23f914f101 fix(platform-browser): Use the right namespace for mathML. (#55622)
Prior to this change, MathML element were created with the wrong namespace resulting in regular DOM `Element`.

This commit fixes this.

Related to #55608 (but doesn't fix it entirely).

PR Close #55622
2024-05-03 08:07:32 -07:00
Andrew Scott
b8c0084c50 refactor(core): Update coalescing to just use patched timers in root zone (#55366)
Rather than attempting to use the native timing functions, this commit
simplifies the logic significantly by using the global timer functions
as they are, either patched or unpatched. When Zone is defined, we run
the timers in the root zone. This has more predictable behavior and
timing than (a) using both patched and unpatched versions of timers in
different places (b) trying to get an unpatched timer and failing due to
environment specifics and patches that aren't ZoneJS.

PR Close #55366
2024-05-02 14:43:10 -07:00
Andrew Kushnir
93dc65a674 refactor(core): mark @defer APIs as stable (#55625)
This commit removes the `@developerPreview` annotation from the `@defer` APIs, effectively promoting them (and the entire feature!) to stable.

PR Close #55625
2024-05-02 14:42:00 -07:00
Rahat Ahmed
662bca47f6 refactor(core): Turn off JSNAMESPACE_SUPPORT by default (#55598)
All usages in google3 have been deleted so this should be a no-op. Next I'll clean up all the configurations turning this off and then delete the option entirely.

PR Close #55598
2024-05-02 12:34:24 -07:00
iteriani
8432d75b9a refactor(core): Remove jsaction from element after handling the event. (#55549)
This also adds a test to make sure that the event contract is still listening to other events, especially in the case where we may want partial hydration in the future.

PR Close #55549
2024-05-02 11:04:59 -07:00
Andrew Scott
243f573797 Revert "fix(core): render hooks should not specifically run outside the Angular zone (#55399)" (#55624)
This reverts commit 7e89753eef.

Running render hooks inside the zone is specifically problematic for
`afterRender` hooks. If the callback has async task, it would cause an
infinite change detection. In addition, updating state in render hooks
is generally discourages and certainly should update state in a way that
notifies Angular of the change (either via signal or with `markForCheck`) rather
than relying on ZoneJS to pick it up (which would only work if the
change is done inside an async task).

PR Close #55624
2024-05-02 11:00:39 -07:00
Andrew Scott
d5edfde6ee fix(core): afterRender hooks registered outside change detection can mark views dirty (#55623)
This commit fixes an error in the looping logic of `ApplicationRef.tick`
when the tick skips straight to render hooks. In this case, if a render
hook makes a state update that requires a view refresh, we would never
actually refresh the view and just loop until we hit the loop limit.

PR Close #55623
2024-05-02 10:58:29 -07:00
Kristiyan Kostadinov
36130b2e72 fix(core): don't schedule timer triggers on the server (#55605)
Fixes that even though we weren't rendering the deferred block the server, we were still triggering the timeout which can delay the response.

Fixes #55475.

PR Close #55605
2024-05-01 15:10:32 -07:00
Tom Wilkinson
4837621df8 refactor(core): Move action resolution into a standalone class. (#55523) (#55621)
This refactor will enable moving this functionality into the dispatcher.

PR Close #55523

PR Close #55621
2024-05-01 15:02:22 -07:00
Tom Wilkinson
7dce62bb05 refactor(core): Remove STOP_PROPAGATION define. (#55582) (#55621)
This define has been removed at head, and now legacy stop propagation
behavior can be opted into at the LegacyDispatcher level, if necessary.

PR Close #55582

PR Close #55621
2024-05-01 15:02:22 -07:00
Tom Wilkinson
d1721c3d51 refactor(core): Add a boostrapCustomEvent method. (#55603) (#55621)
This can replace CUSTOM_EVENT_SUPPORT by allowing users to bootstrap
custom event support separately from the `EventContract`.

PR Close #55603

PR Close #55621
2024-05-01 15:02:22 -07:00
Rahat Ahmed
e58ff4a6dd docs(core): Add event-dispatch README.md (#55521)
PR Close #55521
2024-05-01 11:53:26 -07:00
Andrew Scott
122478c202 refactor(core): Ensure animations are flushed before running render hooks (#55564)
This commit ensures we flush animations by calling renderFactory
begin/end in cases where the ApplicationRef._tick happens in a mode that
skips straight to the render hooks.

PR Close #55564
2024-04-30 15:39:57 -07:00
Pawel Kozlowski
8f99946d1d docs(core): add documentation for errors NG0955 and NG0956 (#55591)
This commit adds detailed description for the errors NG0955 and NG0956.
Those errors correspond to the check introduced in the built-in for loop.

PR Close #55591
2024-04-30 09:21:34 -07:00
Joey Perrott
26ad8dd9f4 refactor: migrate core to prettier formatting (#55488)
Migrate formatting to prettier for core from clang-format

PR Close #55488
2024-04-29 09:49:21 -07:00
Andrew Scott
b5ec30a929 refactor(core): Permit disabling autoDetect for zoneless fixture (#55494)
The caveat here is that this needs to be done before creating the
fixture. There are some technical issues to overcome with disabling it
after it was already enabled, related to detaching from `ApplicationRef`
without other side effects.

PR Close #55494
2024-04-26 09:42:16 -07:00
Kristiyan Kostadinov
f93e5180be fix(migrations): resolve multiple structural issues with HttpClient migration (#55557)
Fixes several issues with the `HttpClient` migration that showed up after I tried updating the Material docs site to the latest v18 release. Includes:
* The migration was assuming that all Angular decorators have at least one argument. This led to a null pointer error that broke the v18 update process when I was testing it.
* The migration incorrectly reimplemented the detection of classes with Angular decorators. This can cause code to be migrated incorrectly and doesn't handle cases like import aliases. I've switched it to use the existing tooling for detecting decorated classes.
* The migration was trying to migrate directives, even though they don't support the `imports` field.
* The migration was detecting `TestBed.configureTestingModule` calls using a raw string match which is very fragile and can be broken by the user's formatting.
* There were syntax errors in the unit tests.
* There were type checking errors in the unit tests, for example none of them were importing the Angular decorators that they were migrating.

There's more room for improvement, but this should resolve the most glaring issues without having to rewrite too much.

PR Close #55557
2024-04-26 09:32:31 -07:00
Matthieu Riegler
21532f8eb8 docs: update ChangeDetectionStrategy links (#55553)
fixes #54227
fixes #50943

PR Close #55553
2024-04-26 09:31:48 -07:00
Andrew Scott
9ec01367b7 refactor(core): Do not duplicate change detection with run coalescing (part 2) (#55403)
This commit prevents doubling change detections when the zoneless
scheduler is notified first, followed by the zone becomeing unstable
(effectively "scheduling" zone-based change detection). When run
coalescing is enabled, this would otherwise result in the zoneless
scheduler running change detection first and then change detection
running again because of the run coalescing since both scheduler use the
same timing function (and then it would be FIFO).

PR Close #55403
2024-04-25 14:31:17 -07:00