Skip to content

Dynamically-created component not removed when zoneless is combined with animations #58075

Closed

Description

@keatkeat87

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

no very sure, but around 18.2.x

Description

Image

The overlay content has not been removed.

Reproduction

StackBlitz link:
Steps to reproduce:

  1. git clone https://github.com/keatkeat87/ng-mat-overlay-detach-issue.git
  2. ng serve
  3. click open and then close.
    Image

if use ZoneChangeDetection, then no problem.

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideAnimations()] // work
  // providers: [provideExperimentalZonelessChangeDetection(), provideAnimations()] // no work
};

only ZonelessChangeDetection have the problem.

if we manual call detectChanges(), then it work.

export class ModalContainerComponent {
  private readonly overlayRef = inject(OverlayRef);
  private cdk = inject(ChangeDetectorRef);

  close() {
    this.overlayRef.detach();
    this.cdk.detectChanges(); // manual detectChanges will work
    // this.cdk.detectChanges(); // without detectChanges no work
  }
}

Expected Behavior

The overlay content should be removed.

Actual Behavior

The overlay content has not been removed.

Environment

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

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

Package Version

@angular-devkit/architect 0.1802.7
@angular-devkit/build-angular 18.2.7
@angular-devkit/core 18.2.7
@angular-devkit/schematics 18.2.7
@angular/cdk 18.2.6
@angular/material 18.2.6
@schematics/angular 18.2.7
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.10

Activity

  1. crisbeto commented on Oct 4, 2024

    @crisbeto
    Member

    This looks like a framework issue. The combination of zoneless and one of the animations modules (either enabled or noop) prevents the element from being removed until the next change detection. I've isolated it in the following Stackblitz: https://stackblitz.com/edit/stackblitz-starters-9p2rdd?file=src%2Fmain.ts

  2. transferred this issue fromangular/componentson Oct 4, 2024
  3. changed the title [-]bug(Overlay): OverlayRef.detach not working when using ZonelessChangeDetection (v18.2.6)[/-] [+]Dynamically-created component not removed when zoneless is combined with animations[/+] on Oct 4, 2024
  4. added
    hotlist: components team
    P2
    core: zoneless
    and removed on Oct 4, 2024
  5. added
    area: animations
    area: core
    on Oct 23, 2024
  6. added this to the Backlog milestone on Oct 23, 2024
  7. added a commit that references this issue on Apr 9, 2025
    0b69b61
  8. angular-automatic-lock-bot commented on May 10, 2025

    @angular-automatic-lock-bot

    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.

  9. locked and limited conversation to collaborators on May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area: animationsarea: corebugcore: zonelesshotlist: components team

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions