handsontable / hyperformula

HyperFormula is an open-source headless spreadsheet for business web apps. It comes with over 400 formulas, CRUD operations, undo-redo, clipboard support, and sorting.
https://hyperformula.handsontable.com/
Other
1.97k stars 108 forks source link

[Bug]: Missing exported changes when batching operations #1291

Closed BrianHung closed 1 year ago

BrianHung commented 1 year ago

Description

When batching an array formula along with neighboring cell values, change values for neighboring cells are not emitted in valuesUpdated or in exported changes when resuming evaluation. Note that values are correctly in hyperformula though (getSheetSerialized is correct).

That means, if we batch an array with a column formula with cells in the same row, none of the cells in the same row will be emitted.

Likewise, if we batch an array with a row formula with cells in the same col, none of the cells in the same col will be emitted.

Batching an array with multiple rows and columns works though.

import HyperFormula from "hyperformula";

const hf = HyperFormula.buildFromSheets(
  {
    Sheet1: [[""]]
  },
  {
    licenseKey: "gpl-v3",
    useArrayArithmetic: true
  }
);

hf.on("valuesUpdated", (changes) => console.log("changes", changes));

const changes = [];
hf.suspendEvaluation();
changes.push(hf.setCellContents({ sheet: 0, row: 0, col: 1 }, "4"));
changes.push(hf.setCellContents({ sheet: 0, row: 0, col: 2 }, "5"));
changes.push(hf.setCellContents({ sheet: 0, row: 0, col: 0 }, "={1;2;3}"));
hf.resumeEvaluation();

console.log("changes after evaluation", changes);

Code sandbox showing it doesnt work row for adjacent col values if array row formula. https://codesandbox.io/s/angry-pond-tmy9fq?file=/src/hyperformulaConfig.js

Code sandbox showing it doesnt work for adjacent row values if array col formula. https://codesandbox.io/s/bold-dawn-w8383q?file=/src/hyperformulaConfig.js

Video or screenshots

No response

Demo

https://codesandbox.io/s/angry-pond-tmy9fq?file=/src/hyperformulaConfig.js

HyperFormula version

2.4.0

Your framework

No response

Your environment

Chrome

adrianszymanski89 commented 1 year ago

Hi @BrianHung

Thank you for reporting this. I also test it in various scenarios, and I can confirm your observations. I'll forward this to our HyperFormula developer for further investigation.

BrianHung commented 1 year ago

@adrianszymanski89 Think I found the bug and implemented a fix: https://github.com/handsontable/hyperformula/pull/1294

By the looks of it, it was a 2 year old bug where the author was refactoring code and forgot to use a new internal utility addressKey when writing new code.

adrianszymanski89 commented 1 year ago

Hi @BrianHung

Thank you for the fix! I'll update our developer about the PR.

AMBudnik commented 1 year ago

I've tested the following demo with Hyperformula 2.5.0 and the build from release branch 2.6.0 and all of the changes are correctly logged in the new version

Hyperformula 2.5.0

Zrzut ekranu 2023-09-14 o 14 03 23

Hyperformula 2.6.0 Zrzut ekranu 2023-09-14 o 14 03 15

AMBudnik commented 1 year ago

Hi @BrianHung

We have an update here as well. I hope you'll benefit from those changes.

ps. If you'd like to know what also changed in the version here are our release notes https://hyperformula.handsontable.com/guide/release-notes.html#_2-6-0