RangeError: Maximum call stack size exceeded when calling core-js Array.flat on deeply nested arrays
25K reputation · 22 Feb 2024, 03:45 UTC
Problem Context
\nWhen using the core-js polyfill for Array.prototype.flat on deeply nested arrays, a RangeError: Maximum call stack size exceeded can be thrown. The polyfill implements a recursive algorithm that follows the ES2022 specification, but it does not guard against stack overflow on highly nested structures.
Unresolved Decision
\ncore-js preserves holes in sparse arrays during flattening, matching the spec. However, older polyfills replace holes with undefined. There is no consensus on whether the polyfill should maintain holes or convert them, and the iterative patch that avoids recursion is not enabled by default.
Key Questions
\n- \n
- Should the core-js
Array.flatpolyfill be modified to replace holes withundefinedto align with some legacy polyfills, or should it continue preserving holes as per the ES2022 spec? \n - Under what circumstances should the iterative patch be enabled to prevent
RangeErroron deeply nested arrays, and what API surface would expose this configuration? \n - What impact would changing hole preservation have on code that relies on the presence of sparse array slots, and how can developers detect such regressions? \n