From cd7248d9e3c0c2f5f766f7dff99190e73367b1b6 Mon Sep 17 00:00:00 2001 From: marcin-kordas-hoc Date: Mon, 16 Nov 2026 09:28:17 +0000 Subject: [PATCH 1/3] Fix IMSUM, IMPRODUCT and TEXTJOIN throwing RangeError for large ranges coerceComplexExactRanges and TEXTJOIN appended a range's values with push(...values), which passes one call argument per value. A range of about 125,000 cells exceeded the call stack and the RangeError escaped the recalculation. The values are now appended in a loop. Co-Authored-By: Claude Opus 5.5 --- hyperformula/dev-docs/INTERPRETER.md | 1 + hyperformula/src/interpreter/ArithmeticHelper.ts | 4 +++- hyperformula/src/interpreter/plugin/TextPlugin.ts | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hyperformula/dev-docs/INTERPRETER.md b/hyperformula/dev-docs/INTERPRETER.md index 192fa1d469..314296ec33 100644 --- a/hyperformula/dev-docs/INTERPRETER.md +++ b/hyperformula/dev-docs/INTERPRETER.md @@ -20,6 +20,7 @@ - **Coerce through `ArithmeticHelper`.** Never write ad-hoc string-to-number or value-to-boolean conversion inside a function; the coercion rules are spreadsheet semantics, not JavaScript semantics, and they are already implemented once. - **Errors are values.** Return a `CellError` with a message from `hyperformula/src/error-message.ts`. Do not throw: a thrown error escapes the evaluation of one cell and takes the recalculation with it. +- **Never spread a range's values into a call.** `push(...values)` and `Math.max(...values)` pass one argument per value, and a range or array of about 125,000 values (Node 24, default stack size) throws `RangeError: Maximum call stack size exceeded` out of the recalculation. Append in a loop. - **The registry is keyed by id, not by implementation.** A custom plugin can be registered over a built-in id. Do not assume the plugin you are reading is the one that will answer for that id at run time. - **Evaluate each argument once.** Evaluating the same argument twice doubles its cost and, when it contains a volatile function such as `RAND`, can see two different values. - **This is the hot path.** `Interpreter.evaluateAst` runs once per formula, and once per cell for array-broadcast arguments. Allocation inside a per-cell loop is measurable. diff --git a/hyperformula/src/interpreter/ArithmeticHelper.ts b/hyperformula/src/interpreter/ArithmeticHelper.ts index 73719a60fb..5d9a833af2 100644 --- a/hyperformula/src/interpreter/ArithmeticHelper.ts +++ b/hyperformula/src/interpreter/ArithmeticHelper.ts @@ -311,7 +311,9 @@ export class ArithmeticHelper { if (arr instanceof CellError) { return arr } else { - expandedVals.push(...arr) + for (const value of arr) { + expandedVals.push(value) + } } } else { expandedVals.push(val) diff --git a/hyperformula/src/interpreter/plugin/TextPlugin.ts b/hyperformula/src/interpreter/plugin/TextPlugin.ts index 066190cac9..9c8d2fe6b4 100644 --- a/hyperformula/src/interpreter/plugin/TextPlugin.ts +++ b/hyperformula/src/interpreter/plugin/TextPlugin.ts @@ -544,7 +544,9 @@ export class TextPlugin extends FunctionPlugin implements FunctionPluginTypechec if (coerced instanceof CellError) { return coerced } - texts.push(...coerced) + for (const text of coerced) { + texts.push(text) + } } const parts = ignoreEmpty ? texts.filter((t) => t !== '') : texts From 860aabef26f28d043f56a1281d16e7aca910e497 Mon Sep 17 00:00:00 2001 From: marcin-kordas-hoc Date: Mon, 16 Nov 2026 09:37:52 +0000 Subject: [PATCH 2/3] Add a changelog entry for the IMSUM, IMPRODUCT and TEXTJOIN RangeError fix Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2bb891fc2..1bee4ff956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fixed functions such as `MATCH`, `INDEX` and `COUNTIF` throwing an uncaught `Unknown array` error when they read a range that exactly matches the area of an array formula returning an error, for example `=MATCH(2, B1:B3, 0)` next to `=SORT(A1:A3)` whose source contains `#DIV/0!`. They now read the range cell by cell. [#1876](https://github.com/handsontable/hyperformula/pull/1876) - Fixed unbounded parser cache growth in long-running instances that process many distinct formulas, including when undo is disabled. [#1635](https://github.com/handsontable/hyperformula/issues/1635) - Fixed array formulas spilling past the `maxRows` and `maxColumns` limits: they now return `#SPILL!` when their result extends beyond the sheet edge. [#1774](https://github.com/handsontable/hyperformula/pull/1774) +- Fixed `IMSUM`, `IMPRODUCT` and `TEXTJOIN` throwing an uncaught `RangeError` for very large ranges, such as `=IMSUM(A1:D40000)`, which stopped the recalculation; they now return a result or an error value in the cell. ## [3.5.0] - 2026-10-09 From 8fb808f6b486c2d77678e12c3858c395b88d0430 Mon Sep 17 00:00:00 2001 From: marcin-kordas-hoc Date: Tue, 17 Nov 2026 04:14:46 +0000 Subject: [PATCH 3/3] Link the changelog entry to #1901 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bee4ff956..5a94003915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fixed functions such as `MATCH`, `INDEX` and `COUNTIF` throwing an uncaught `Unknown array` error when they read a range that exactly matches the area of an array formula returning an error, for example `=MATCH(2, B1:B3, 0)` next to `=SORT(A1:A3)` whose source contains `#DIV/0!`. They now read the range cell by cell. [#1876](https://github.com/handsontable/hyperformula/pull/1876) - Fixed unbounded parser cache growth in long-running instances that process many distinct formulas, including when undo is disabled. [#1635](https://github.com/handsontable/hyperformula/issues/1635) - Fixed array formulas spilling past the `maxRows` and `maxColumns` limits: they now return `#SPILL!` when their result extends beyond the sheet edge. [#1774](https://github.com/handsontable/hyperformula/pull/1774) -- Fixed `IMSUM`, `IMPRODUCT` and `TEXTJOIN` throwing an uncaught `RangeError` for very large ranges, such as `=IMSUM(A1:D40000)`, which stopped the recalculation; they now return a result or an error value in the cell. +- Fixed `IMSUM`, `IMPRODUCT` and `TEXTJOIN` throwing an uncaught `RangeError` for very large ranges, such as `=IMSUM(A1:D40000)`, which stopped the recalculation; they now return a result or an error value in the cell. [#1901](https://github.com/handsontable/hyperformula/pull/1901) ## [3.5.0] - 2026-10-09