Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation not initialized when using ZonelessChangeDetection #54919

Closed
keatkeat87 opened this issue Mar 18, 2024 · 2 comments
Closed

Animation not initialized when using ZonelessChangeDetection #54919

keatkeat87 opened this issue Mar 18, 2024 · 2 comments
Assignees
Labels
area: core Issues related to the framework runtime area: zones P4 A relatively minor issue that is not relevant to core functions
Milestone

Comments

@keatkeat87
Copy link

Which @angular/* package(s) are the source of the bug?

animations

Is this a regression?

No

Description

a simple reproduction

app.config.ts

export const appConfig: ApplicationConfig = {
  providers: [provideAnimationsAsync(), ɵprovideZonelessChangeDetection()]
};

app.component.ts

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [],
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
  animations: [
    trigger('highlight', [
      state('false', style({ 'background-color': 'red', color: 'white' })),
    ])
  ]
})
export class AppComponent {
  highlight = signal(false);
}

app.component.html
<h1 [@highlight]="highlight()">Hello World</h1>

results:
if no apply ɵprovideZonelessChangeDetection()
image
if apply ɵprovideZonelessChangeDetection()
image

Please provide a link to a minimal reproduction of the bug

https://github.com/keatkeat87/zoneless-animation-issue

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.3.0
Node: 20.11.1
Package Manager: yarn 1.22.19
OS: win32 x64

Angular: 17.3.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.0
@angular-devkit/build-angular   17.3.0
@angular-devkit/core            17.3.0
@angular-devkit/schematics      17.3.0
@schematics/angular             17.3.0
rxjs                            7.8.1
typescript                      5.4.2
zone.js                         0.14.4

Anything else?

No response

@atscott atscott self-assigned this Mar 18, 2024
@atscott
Copy link
Contributor

atscott commented Mar 18, 2024

Async animations currently relies on the import promise being detected by ZoneJS and triggering another round of change detection.

@ngbot ngbot bot added this to the needsTriage milestone Mar 18, 2024
@atscott atscott added area: core Issues related to the framework runtime P4 A relatively minor issue that is not relevant to core functions labels Mar 18, 2024
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 18, 2024
atscott added a commit to atscott/angular that referenced this issue Mar 28, 2024
This change ensures the scheduler is notified when an animation trigger
updates. This requires change detection to run to flush the animations.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Mar 29, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Mar 29, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Mar 29, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 5, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 5, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 5, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 5, 2024
…in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 12, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 12, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 12, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 15, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 15, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 15, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 18, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 22, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 22, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 23, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 23, 2024
…aded in zoneless

Async animations currently works in Zones because the render factory
promise resolve causes change detection to happen.

fixes angular#54919
atscott added a commit to atscott/angular that referenced this issue Apr 24, 2024
… ZoneJS (angular#55492)

In Angular today, a bound listener automatically marks the view for
check. When using ZoneJS, these listeners are most often executed in the
Angular Zone as well, so synchronization (`ApplicationRef.tick`) will
eventually happen. _However_, developers can opt out of zone-patching
for events in several ways, and often do this for very frequent
listeners like `mousemove`, `resize`, and `scroll`. We do not want to
break existing expectations that these are now "safe" events to have
listeners for by automatically scheduling change detection regardless of
whether the listener executed inside or outside the Angular zone.

In contrast, in order for developers to more easily transition to zoneless,
we need to be able to ensure that components which are using `OnPush`
are, for the most part, compatible with zoneless as well. Because listeners
automatically mark the component for check, developers using `OnPush`
did not/do not need to also call `ChangeDetectorRef.markForCheck` or a
similar API. Unfortunately, this means that we need to consider the
listener callbacks as a notification to schedule a `tick` when Zoneless
is enabled. In the future, we would like to have an opt-out for this
(i.e. signal components) since it's not really how we _want_ things to work.

Also includes the fix for angular#54919 that got reverted only because it was
easier to revert the set of conflicting commits
atscott added a commit to atscott/angular that referenced this issue Apr 24, 2024
… ZoneJS (angular#55492)

In Angular today, a bound listener automatically marks the view for
check. When using ZoneJS, these listeners are most often executed in the
Angular Zone as well, so synchronization (`ApplicationRef.tick`) will
eventually happen. _However_, developers can opt out of zone-patching
for events in several ways, and often do this for very frequent
listeners like `mousemove`, `resize`, and `scroll`. We do not want to
break existing expectations that these are now "safe" events to have
listeners for by automatically scheduling change detection regardless of
whether the listener executed inside or outside the Angular zone.

In contrast, in order for developers to more easily transition to zoneless,
we need to be able to ensure that components which are using `OnPush`
are, for the most part, compatible with zoneless as well. Because listeners
automatically mark the component for check, developers using `OnPush`
did not/do not need to also call `ChangeDetectorRef.markForCheck` or a
similar API. Unfortunately, this means that we need to consider the
listener callbacks as a notification to schedule a `tick` when Zoneless
is enabled. In the future, we would like to have an opt-out for this
(i.e. signal components) since it's not really how we _want_ things to work.

Also includes the fix for angular#54919 that got reverted only because it was
easier to revert the set of conflicting commits
AndrewKushnir pushed a commit that referenced this issue Apr 25, 2024
… ZoneJS (#55492) (#55525)

In Angular today, a bound listener automatically marks the view for
check. When using ZoneJS, these listeners are most often executed in the
Angular Zone as well, so synchronization (`ApplicationRef.tick`) will
eventually happen. _However_, developers can opt out of zone-patching
for events in several ways, and often do this for very frequent
listeners like `mousemove`, `resize`, and `scroll`. We do not want to
break existing expectations that these are now "safe" events to have
listeners for by automatically scheduling change detection regardless of
whether the listener executed inside or outside the Angular zone.

In contrast, in order for developers to more easily transition to zoneless,
we need to be able to ensure that components which are using `OnPush`
are, for the most part, compatible with zoneless as well. Because listeners
automatically mark the component for check, developers using `OnPush`
did not/do not need to also call `ChangeDetectorRef.markForCheck` or a
similar API. Unfortunately, this means that we need to consider the
listener callbacks as a notification to schedule a `tick` when Zoneless
is enabled. In the future, we would like to have an opt-out for this
(i.e. signal components) since it's not really how we _want_ things to work.

Also includes the fix for #54919 that got reverted only because it was
easier to revert the set of conflicting commits

PR Close #55525
AndrewKushnir pushed a commit that referenced this issue Apr 25, 2024
… ZoneJS (#55492) (#55525)

In Angular today, a bound listener automatically marks the view for
check. When using ZoneJS, these listeners are most often executed in the
Angular Zone as well, so synchronization (`ApplicationRef.tick`) will
eventually happen. _However_, developers can opt out of zone-patching
for events in several ways, and often do this for very frequent
listeners like `mousemove`, `resize`, and `scroll`. We do not want to
break existing expectations that these are now "safe" events to have
listeners for by automatically scheduling change detection regardless of
whether the listener executed inside or outside the Angular zone.

In contrast, in order for developers to more easily transition to zoneless,
we need to be able to ensure that components which are using `OnPush`
are, for the most part, compatible with zoneless as well. Because listeners
automatically mark the component for check, developers using `OnPush`
did not/do not need to also call `ChangeDetectorRef.markForCheck` or a
similar API. Unfortunately, this means that we need to consider the
listener callbacks as a notification to schedule a `tick` when Zoneless
is enabled. In the future, we would like to have an opt-out for this
(i.e. signal components) since it's not really how we _want_ things to work.

Also includes the fix for #54919 that got reverted only because it was
easier to revert the set of conflicting commits

PR Close #55525
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime area: zones P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
2 participants