Skip to content

fix(@angular-devkit/schematics): avoid stack overflow when chaining many rules - #34338

Open
adiyy2001 wants to merge 1 commit into
angular:mainfrom
adiyy2001:fix/schematics-chain-stack-overflow
Open

adiyy2001 wants to merge 1 commit into
angular:mainfrom
adiyy2001:fix/schematics-chain-stack-overflow

Conversation

@adiyy2001

Copy link
Copy Markdown

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

chain() builds one nested observable per rule. With a few thousand rules, subscribing to the result goes past the call stack limit. Locally, 2000 no-op rules gave a promise that never settled, and the issue reports RangeError: Maximum call stack size exceeded.

Issue Number: #17851

What is the new behavior?

chain() awaits each rule's result before calling the next rule, so the stack depth no longer grows with the number of rules. The new spec in base_spec.ts chains 20000 rules. It times out on main and passes with this change.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Tested with bazel test //packages/angular_devkit/schematics/... //packages/schematics/angular:test //packages/angular_devkit/schematics_cli/....

Closes #17851

…any rules

The chain rule nested one observable per rule, so subscribing to a chain of a
few thousand rules exceeded the call stack and the result never settled. Each
rule result is now awaited before the next rule runs.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the chain rule execution in Angular DevKit Schematics to process rules sequentially using await lastValueFrom instead of chaining Observables. This prevents potential stack overflow issues when executing a large number of rules, which is verified by a new test case running 20,000 rules. There are no review comments to address, and we have no additional feedback to provide.

@clydin clydin added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Oct 13, 2026
@alan-agius4 alan-agius4 removed the action: merge The PR is ready for merge by the caretaker label Oct 13, 2026
@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular-devkit/schematics target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular Schematics - Apply thousands of changes on tree cause error "Maximum call stack size exceeded"

3 participants