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

bug(cdk/tree): RangeError: Maximum call stack size exceeded #29733

Closed
1 task done
kfrederix opened this issue Sep 13, 2024 · 2 comments · Fixed by #29754
Closed
1 task done

bug(cdk/tree): RangeError: Maximum call stack size exceeded #29733

kfrederix opened this issue Sep 13, 2024 · 2 comments · Fixed by #29754
Assignees
Labels
area: cdk/tree P2 The issue is important to a large percentage of users, with a workaround

Comments

@kfrederix
Copy link

kfrederix commented Sep 13, 2024

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

18.1.4

Description

Starting from @angular/cdk version 18.2.0, a bug got introduced which causes "Maximum call stack size exceeded" errors when we have a tree node with many dynamic children. From our observations, it can start already from +/- 500 child nodes.
It does not need to be deeply nested, just 1 level deep is enough, but the amount of child nodes matters.

I have not been able to reproduce it with flat cdk-tree-node, only when using the cdk-nested-tree-node. Even then, it only seems to happen when loading children dynamically plus timing (network delay) also seems to play a role.

The errors look like this:

image

NOTE: it can also be reproduced using the treeControl instead of childrenAccessor (like we would write it before v18.2.0). That makes no difference. Please let me know if you would like to see an example of that on StackBlitz as well...

Reproduction

StackBlitz link: https://stackblitz.com/edit/qmvryx-5s6t5r?file=src%2Fexample%2Fcdk-tree-nested-children-accessor-example.ts
Steps to reproduce:

  1. visit above StackBlitz link
  2. Open JS console
  3. Expand the Root node
  4. Observe errors is JS console

Expected Behavior

No errors in console.

Actual Behavior

An explosion of errors: RangeError: Maximum call stack size exceeded

Environment

Angular CLI: 18.2.4
Node: 20.12.2
Package Manager: pnpm 9.8.0
OS: win32 x64

Angular: 18.2.4
... animations, build, cli, common, compiler, compiler-cli, core
... forms, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1802.4 (cli-only)
@angular-devkit/core 18.2.4 (cli-only)
@angular-devkit/schematics 18.2.4 (cli-only)
@angular/cdk 18.2.3
@angular/material 18.2.3
@schematics/angular 18.2.4
rxjs 7.8.1
typescript 5.5.4
webpack 5.91.0
zone.js 0.14.10

@kfrederix kfrederix added the needs triage This issue needs to be triaged by the team label Sep 13, 2024
@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround area: cdk/tree and removed needs triage This issue needs to be triaged by the team labels Sep 13, 2024
@crisbeto crisbeto self-assigned this Sep 18, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 18, 2024
The CDK tree was calling `ChangeDetectorRef.detectChanges` recursively for each node in the tree which was overflowing the call stack with some larger trees.

These changes resolve the issue by only calling `detectChanges` on the root.

Fixes angular#29733.
crisbeto added a commit that referenced this issue Sep 18, 2024
The CDK tree was calling `ChangeDetectorRef.detectChanges` recursively for each node in the tree which was overflowing the call stack with some larger trees.

These changes resolve the issue by only calling `detectChanges` on the root.

Fixes #29733.

(cherry picked from commit be004b8)
@kfrederix
Copy link
Author

Thank you for the super fast fix! 🙌

@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 Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/tree P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants