-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
"Uncaught RangeError: Maximum call stack size exceeded" when parent element not in DOM tree yet #7761
Comments
Does not reproduce in master: https://codepen.io/kurkle/pen/BaKPRQG?editors=1010 |
Hello @kurkle , I know that it works on the 3.0 version, but I hoped that it could be fixed (I kind of did) in the 2.9 version. |
Not sure how difficult the fix would be. Most of the related code is changed in v3, so I don't think the fix can be back ported. Personally I'm not interested in investigating this, but would probably review a pr for it. |
Adding a verification on updateDims that handles a case when dimensions are both NaN. This caused an infinite recursion on fitBoxes when calculating the layout for a chart that is mounted on an element that is not yet in DOM. Fixes chartjs#7761
Adding a verification on updateDims that handles a case when dimensions are both NaN. This caused an infinite recursion on fitBoxes when calculating the layout for a chart that is mounted on an element that is not yet in DOM. Fixes chartjs#7761
* Infinite recursion when dimensions are NaN Adding a verification on updateDims that handles a case when dimensions are both NaN. This caused an infinite recursion on fitBoxes when calculating the layout for a chart that is mounted on an element that is not yet in DOM. Fixes #7761
I noticed that when creating a Chart appended to an element that is still not in the DOM tree you end up with a
Maximum call stack
error because of an infinite recursive call infitBoxes
method. This happens when theresponsive
option is true and when using multipleyAxes
.It's quite common in modern frameworks that elements are created before they are added to the DOM tree (and added when data are ready). I noticed the issue using the
ng2-charts
component in an Angular project.The issue has been introduced in 2.9 version (previous versions works fine).
Expected Behavior
The chart should be created without errors, or the render should stop with a more clear error.
Current Behavior
A
Maximum call stack
error is shown in the console.Possible Solution
The problem could also be solved simply checking if the parent element can be found in the DOM tree and stop the render with an error.
The cause of the issue is that the
getMaximumWidth
(andgetMaximumHeight
) helper returnsNaN
in this condition.A solution could be to change the
_calculatePadding
private helper to manage theNaN
value returned by theparseInt
method. ThegetStyle
helper could also be changed to try to get the property from the element style in case thegetComputedStyle
method returns an empty string.I made some changes, created a test which fails with the actual code and tested my new code against all other tests: I can do a
pull request, so you can have a look at it.
Steps to Reproduce
I created a codepen with a code example, but sadly it doesn't show the maximum call stack error. Anyway, you can easily reproduce the error copying the code on a local project and get the error in the console.
https://codepen.io/nuandawm/pen/bGpYQKJ
Context
Environment
The text was updated successfully, but these errors were encountered: