Skip to content

RangeError: Maximum call stack size exceeded in @angular/animations module #38551

Closed

Description

@th0r

🐞 bug report

Affected Package

The issue is caused by package @angular/animations

Is this a regression?

Not sure

Description

We sometimes see RangeError: Maximum call stack size exceeded error in our production environment. Some of them come from Safari, some from Chrome. I'm attaching a few last frames of the stacktrace (see the section below). I think this is the reason for the issue: https://anchortagdev.com/range-error-maximum-call-stack-size-exceeded-error-using-spread-operator-in-node-js-javascript. Looks like it happens when page contains a lot of DOM elements and code tries to push them all into an array using a spread operator.

🔬 Minimal Reproduction

Sorry, I don't know how to reproduce it.

🔥 Exception or Error

image

🌍 Your Environment

Angular Version:




Angular CLI: 9.1.5
Node: 12.16.1
OS: darwin x64

Angular: 9.1.6
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router, upgrade
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.5
@angular-devkit/build-angular     0.901.5
@angular-devkit/build-optimizer   0.901.5
@angular-devkit/build-webpack     0.901.5
@angular-devkit/core              7.3.10
@angular-devkit/schematics        7.3.10
@angular/cdk                      9.2.3
@angular/cli                      9.1.5
@ngtools/webpack                  9.1.5
@schematics/angular               9.1.5
@schematics/update                0.901.5
rxjs                              6.5.5
typescript                        3.7.5
webpack                           4.43.0

Activity

  1. added
    area: animations
    on Aug 21, 2020
  2. added this to the needsTriage milestone on Aug 21, 2020
  3. changed the title [-]`RangeError: Maximum call stack size exceeded` in `@angular/animations` module in Safari[/-] [+]`RangeError: Maximum call stack size exceeded` in `@angular/animations` module[/+] on Sep 3, 2020
  4. th0r commented on Sep 15, 2020

    @th0r
    Author

    Any feedback folks?

  5. AleksanderBodurri commented on Sep 19, 2020

    @AleksanderBodurri
    Member

    This issue got me really curious so I did some benchmarking with https://jsbench.me

    https://jsbench.me/jvkf8ynmgg/1

    Each test creates 1000 divs before the test case runs and assigns the result to a variable.

    1. nodeList kept as a NodeList

    Screen Shot 2020-09-18 at 9 07 20 PM

    1. nodeList converted into an Array (This one is unrelated to this issue but I thought it was interesting)

    Screen Shot 2020-09-18 at 9 08 13 PM

    Relevant code

    _query = (element: any, selector: string, multi: boolean): any[] => {
    let results: any[] = [];
    if (multi) {
    results.push(...element.querySelectorAll(selector));
    } else {
    const elm = element.querySelector(selector);
    if (elm) {
    results.push(elm);
    }
    }
    return results;
    };

    Maybe changing

         results.push(...element.querySelectorAll(selector)); 

    to

        const elements = element.querySelectorAll(selector);
        for (let i = 0, l = elements.length; i < l; i++) {
           results.push(elements[i]);
        }

    might resolve this issue and potentially offer a performance increase.

  6. added
    open for contributions
    P4
    on Oct 26, 2020
  7. modified the milestones: needsTriage, Backlog on Oct 26, 2020
  8. jelbourn commented on Oct 26, 2020

    @jelbourn
    Contributor

    While we can't reproduce this issue, it looks like the function @AleksanderBodurri mentions could be simplified anyway to something like this:

    _query = (element: any, selector: string, multi: boolean): any[] => {
        if (multi) {
            return Array.from(element.querySelectorAll(selector));
        } else {
          const elm = element.querySelector(selector);
          return elm ? [elm] : [];  
        }
      };

    Feel free to send a PR

  9. added
    needs reproduction
    on Oct 26, 2020
  10. added a commit that references this issue on Nov 25, 2020
    e95cd2a
  11. angular-automatic-lock-bot commented on Dec 26, 2020

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

  12. locked and limited conversation to collaborators on Dec 26, 2020
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

    P4area: animationsneeds reproductionopen for contributions

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions