Skip to content

ChangeDetectorRef#detectChanges() causes error in NgForOf directive #45417

Closed

Description

@amitbeck

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

common

Is this a regression?

No

Description

For some reason, calling ChangeDetectorRef#detectChanges() causes an error in NgForOf directive where view is null and therefore when calling viewContainer.move() there's a runtime TypeError due to attempting to read properties of null (see attached stack trace)

const view = viewContainer.get(adjustedPreviousIndex)!;
viewContainer.move(view, currentIndex);

override move(viewRef: ViewRef, newIndex: number): ViewRef {
if (ngDevMode && viewRef.destroyed) {

I managed to workaround this by calling ChangeDetectorRef#detectChanges() within window.setTimeout()'s callback.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

TypeError: Cannot read properties of null (reading 'destroyed')
    at ViewContainerRef.move (core.mjs:22916:1)
    at common.mjs:3194:31
    at DefaultIterableDiffer.forEachOperation (core.mjs:27491:1)
    at NgForOf._applyChanges (common.mjs:3182:17)
    at NgForOf.ngDoCheck (common.mjs:3177:22)
    at callHook (core.mjs:2552:1)
    at callHooks (core.mjs:2511:1)
    at executeCheckHooks (core.mjs:2443:1)
    at selectIndexInternal (core.mjs:8399:1)
    at Module.ɵɵadvance (core.mjs:8388:1)

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

Angular: 13.2.4
... animations, cdk, cdk-experimental, common, compiler
... compiler-cli, core, forms, language-service, localize
... material, platform-browser, platform-browser-dynamic, router
... service-worker, upgrade

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1302.5
@angular-devkit/build-angular   13.2.5
@angular-devkit/core            13.2.5
@angular-devkit/schematics      13.2.5
@angular/cli                    13.2.5
@schematics/angular             13.2.5
rxjs                            7.5.4
typescript                      4.5.5

Anything else?

Possibly related to NativeScript/nativescript-angular#1221 (comment)

Activity

  1. JoostK commented on Mar 23, 2022

    @JoostK
    Member

    Can you share a runnable reproduction please?

  2. added
    area: common
    needs reproduction
    area: core
    on Mar 23, 2022
  3. modified the milestone: Backlog on Mar 23, 2022
  4. jessicajaniuk commented on Mar 28, 2022

    @jessicajaniuk
    Contributor

    I'm sorry but we can't reproduce the problem you are reporting. We require that reported issues have a minimal reproduction that showcases the problem.

    If the problem still exists in your application, please open a new issue and follow the instructions in the issue template that include info on how to create a reproduction using our template.

  5. angular-automatic-lock-bot commented on Apr 28, 2022

    @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.

  6. locked and limited conversation to collaborators on Apr 28, 2022
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

    area: commonarea: coreneeds reproduction

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions