0

How can i solve this problem ?

function flatten(arrays) {
    return [].concat.apply([], arrays);
}


Uncaught (in promise) RangeError: Maximum call stack size exceeded
at flatten (html2canvas.js:2650)
at new NodeParser (html2canvas.js:1861)
at renderWindow (html2canvas.js:1019)
at html2canvas.js:1006
at <anonymous>

Please help

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Kel
  • 55
  • 3
  • 12
  • related: http://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept – Kaiido Nov 06 '17 at 01:57

1 Answers1

1

You probably passed a large number of arrays into the function. You can try something like this instead:

function flatten(arrays){
    return arrays.reduce(function(prev, curr){
        return prev.concat(curr);
    }, []);
}

var matrix = [
    [1, 2],
    [3, 4]
];
flatten(matrix);    // [1, 2, 3, 4]
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
  • That's a good idea, but since the error is raised in html2canvas.js:2650, I think OP should rather raise an issue on the [github's project](https://github.com/niklasvh/html2canvas). – Kaiido Nov 06 '17 at 01:57
  • 1
    The `flatten` function actually comes from some other sources (probably from Babel), so I'm not sure where the bug should be reported to. – Derek 朕會功夫 Nov 06 '17 at 02:06
  • I tried this code on html2canvas.js. There's no error, but its not rendering either. I tried to add a 'log()' on 'function flatten' it becomes infinite loop. My pages has 40,000 pixel height and there's so many elements to render.The version of html2canvas is 0.5.0-beta4 – Kel Nov 06 '17 at 02:56
  • @Kel It's probably taking a very long time to concatenate all the rows given that you had so many rows (>65536). – Derek 朕會功夫 Nov 06 '17 at 03:05
  • even if i added the "type : 'view' " in the html2canvas ? – Kel Nov 06 '17 at 03:10
  • I'm not familiar with the library, but since it exceeded the max stack size, I would assume the matrix has way too many rows in it. – Derek 朕會功夫 Nov 06 '17 at 03:12
  • Thanks!! I tried to wait for it. Its all good now. It renders the whole page then cut it down on what the user can see in the viewport. Thats why its too slow. – Kel Nov 06 '17 at 03:18
  • There might be ways to speed it up by not using `.concat`, but I prefer to leave the optimization for the developer himself. – Derek 朕會功夫 Nov 06 '17 at 05:35