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

Maximum call stack size exceeded with large SVG #45564

Closed
2 of 15 tasks
jaredtbates opened this issue Apr 8, 2022 · 4 comments
Closed
2 of 15 tasks

Maximum call stack size exceeded with large SVG #45564

jaredtbates opened this issue Apr 8, 2022 · 4 comments
Assignees
Labels
area: compiler Issues related to `ngc`, Angular's template compiler P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR
Milestone

Comments

@jaredtbates
Copy link

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 13.2.2 (I think)

We noticed this while upgrading from Angular 12 to 13. For now, we will upgrade to 13.2.2 instead of the latest.

Description

When compiling an app that has a large SVG in a template, the build fails with a "Maximum call stack size exceeded" error. This happens on both ng serve and ng build.

Please note: I understand my minimal reproduction may not be the ideal way to host SVGs in templates, however this is a rudimentary example to replicate an issue that we are seeing in our codebase. Thanks for understanding!

🔬 Minimal Reproduction

https://github.com/sightsoundtheatres/call-stack-repro

🔥 Exception or Error

./src/app/app.component.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Maximum call stack size exceeded
    at /Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@ngtools/webpack/src/ivy/loader.js:81:18
    at runMicrotasks ()
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
 [webpack-dev-middleware] RangeError: Maximum call stack size exceeded
     at InvokeFunctionExpr.visitExpression (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler/fesm2015/compiler.mjs:1616:20)
     at ExpressionTranslatorVisitor.visitInvokeFunctionExpr (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler-cli/bundles/chunk-IZWUTMTT.js:839:76)
     at InvokeFunctionExpr.visitExpression (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler/fesm2015/compiler.mjs:1617:24)
     at ExpressionTranslatorVisitor.visitInvokeFunctionExpr (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler-cli/bundles/chunk-IZWUTMTT.js:839:76)
     at InvokeFunctionExpr.visitExpression (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler/fesm2015/compiler.mjs:1617:24)
     at ExpressionTranslatorVisitor.visitInvokeFunctionExpr (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler-cli/bundles/chunk-IZWUTMTT.js:839:76)
     at InvokeFunctionExpr.visitExpression (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler/fesm2015/compiler.mjs:1617:24)
     at ExpressionTranslatorVisitor.visitInvokeFunctionExpr (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler-cli/bundles/chunk-IZWUTMTT.js:839:76)
     at InvokeFunctionExpr.visitExpression (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler/fesm2015/compiler.mjs:1617:24)
     at ExpressionTranslatorVisitor.visitInvokeFunctionExpr (file:///Users/jared.bates/Code/Frontend/call-stack-repro/node_modules/@angular/compiler-cli/bundles/chunk-IZWUTMTT.js:839:76)

🌍 Your Environment


Angular CLI: 13.3.2
Node: 16.14.2
Package Manager: npm 8.5.5
OS: darwin arm64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.2
@angular-devkit/build-angular   13.3.2
@angular-devkit/core            13.3.2
@angular-devkit/schematics      13.3.2
@schematics/angular             13.3.2
rxjs                            7.5.5
typescript                      4.6.3

Anything else relevant?

If I run node --stack-size=10000 ./node_modules/.bin/ng serve the program builds and serves just fine. However, this is obviously not an ideal solution.

@alan-agius4 alan-agius4 transferred this issue from angular/angular-cli Apr 8, 2022
@alan-agius4 alan-agius4 added the area: compiler Issues related to `ngc`, Angular's template compiler label Apr 8, 2022
@ngbot ngbot bot added this to the needsTriage milestone Apr 8, 2022
@JoostK
Copy link
Member

JoostK commented Apr 8, 2022

This is caused by #44994, which did indeed land in 13.2.3. We should probably limit the chaining depth to a certain maximum to avoid such deeply nested function calls.

@crisbeto FYI

@JoostK JoostK added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Apr 8, 2022
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 8, 2022
@crisbeto
Copy link
Member

crisbeto commented Apr 8, 2022

I suspect that this has less to do with the fact that we're chaining and more that all our walker logic is based on recursion.

@JoostK
Copy link
Member

JoostK commented Apr 8, 2022

Yeah that is pretty common as it's all visitors; the problem is how a linear sequence of elements (which is not susceptible to stack depth limits) becomes a nested hierarchy of call expressions (and therefore stack depth becomes a limitation due to the recursive nature of visitors)

@crisbeto crisbeto self-assigned this Apr 9, 2022
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 9, 2022
Our logic for generating code from an AST uses recursion which limits the number of expressions we can nest before we reach the call stack limit. These changes add a limit in order to avoid errors in some cases where the chains become extremely long.

Fixes angular#45564.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 9, 2022
Our logic for generating code from an AST uses recursion which limits the number of expressions we can nest before we reach the call stack limit. These changes add a limit in order to avoid errors in some cases where the chains become extremely long.

Fixes angular#45564.
jessicajaniuk pushed a commit that referenced this issue Apr 13, 2022
…45574)

Our logic for generating code from an AST uses recursion which limits the number of expressions we can nest before we reach the call stack limit. These changes add a limit in order to avoid errors in some cases where the chains become extremely long.

Fixes #45564.

PR Close #45574
@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 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants