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/
GNU General Public License v3.0
1.88k stars 107 forks source link

[Bug]: In a specific combination of adding rows, content, and column amount alteration we get `Uncaught Error` from the `DenseStrategy` #1406

Open AMBudnik opened 2 months ago

AMBudnik commented 2 months ago

Description

In a specific combination of adding rows, content, and column amount alteration we get Uncaught Error from the DenseStrategy.

Case 1

Case 2

Video or screenshots

Error for column addition

Uncaught TypeError: Cannot read properties of undefined (reading 'splice')
    at DenseStrategy.addColumns (hyperformula.js?v=bfc9e82e:14088:23)
    at AddressMapping.addColumns (hyperformula.js?v=bfc9e82e:11312:18)
    at hyperformula.js?v=bfc9e82e:13184:27
    at EmptyStatistics.measure (hyperformula.js?v=bfc9e82e:10956:20)
    at _DependencyGraph.addColumns (hyperformula.js?v=bfc9e82e:13183:16)
    at Operations.doAddColumns (hyperformula.js?v=bfc9e82e:18737:30)
    at Operations.addColumns (hyperformula.js?v=bfc9e82e:18183:12)
    at CrudOperations.addColumns (hyperformula.js?v=bfc9e82e:19594:21)
    at _HyperFormula.addColumns (hyperformula.js?v=bfc9e82e:23494:26)
    at main.js:45:4

Error for column removal

Uncaught TypeError: Cannot read properties of undefined (reading 'splice')
    at DenseStrategy.removeColumns (hyperformula.js?v=dabf68a5:14100:23)
    at AddressMapping.removeColumns (hyperformula.js?v=dabf68a5:11319:18)
    at hyperformula.js?v=dabf68a5:13147:27
    at EmptyStatistics.measure (hyperformula.js?v=dabf68a5:10956:20)
    at _DependencyGraph.removeColumns (hyperformula.js?v=dabf68a5:13146:16)
    at Operations.doRemoveColumns (hyperformula.js?v=dabf68a5:18678:30)
    at Operations.removeColumns (hyperformula.js?v=dabf68a5:18189:35)
    at CrudOperations.removeColumns (hyperformula.js?v=dabf68a5:19602:45)
    at _HyperFormula.removeColumns (hyperformula.js?v=dabf68a5:23567:26)
    at main.js:45:4

Demo

{column addition} https://stackblitz.com/edit/vitejs-vite-w55sez?file=index.html,main.js&terminal=dev ; {column removal} https://stackblitz.com/edit/vitejs-vite-1ssmt8?file=index.html,main.js&terminal=dev

HyperFormula version

2.7.0

Your framework

Vanilla JS

Your environment

Chrome 123, macOS Ventura

sequba commented 2 months ago

Once it's fixed in the HperFormula, we should verify if the analogous scenario is working correctly in Handsontable

richcanvas commented 2 months ago

i also have this error as the following simple case: let data=[ [], [,1], [,2], [,'=sum(B2:B3)'] ] const options = {licenseKey: 'gpl-v3',} let hf=HyperFormula.buildEmpty(options) hf.addSheet('sheet1') hf.setSheetContent(0,data) let can=hf.isItPossibleToRemoveColumns(0,[0,1]) console.log(can) let changes=hf.removeColumns(0,[0,1]) //throw exception

it's ok to call HyperFormula.buildFromSheets(xxx)

AMBudnik commented 2 months ago

Thank you for sharing the scenario, @richcanvas we will test it as well and update you upon fix.