handsontable / handsontable

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

Home Page:https://handsontable.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: getCellsMeta return stale result if row and column have been inserted

ornoone opened this issue · comments

Describe the bug

minimal reproduction project here: https://github.com/ornoone/handsontable-bug-reproduction-metadata

setup: latest jest + handsontable + jest-environment-jsdom

bug :

(all this changes are set programaticaly via `setCellMeta()` and `alter()` and data are read via  `getCellsMeta()` and `getCellMeta()`
1. insert cell meta into a cell (A1)
2. insert a row before A1 : this move  A1 to A2
3. insert a column before A1 : this move A2 to B2 

A. doing getCellMeta(1, 1) return our metadata :+1: 
B. searching through the metadata (via getCellsMeta()) return our metadata at A2 instead of B2

all this behavior is described in the tests of the reproduction project, with very minimalist code

the workaround I have found is to call getCellMeta() before scanning because it seem it make getCellsMeta() scan up to date data.
the bug seem to be there since at least handsontable@12.1.2

Video/Screenshots

No response

Provide a link to the demo with the bug reproduction

https://github.com/ornoone/handsontable-bug-reproduction-metadata

Handsontable version

12, 13, 14

Framework version

reproduction without framework

Your environment

debian 12
Node.js v18.19.1

Hi @ornoone

I tried to recreate this scenario in a simplified demo, but it returned the correct indexes. After adding a new row and column, the custom cell meta is found at indexes 1, 1. Here's an example: https://jsfiddle.net/handsoncode/pv56u0gc/

hello @adrianszymanski89 , thanks for your fast reply, and sorry for the late follow up.

it seem the problem is indeed related to the use of jest+jsdom, because I don't have the problem on the real application running in a browser. it confirm the fact your jsfiddle work too.

still, given the very small set of dependencies to reproduce the behavior, it's possible other people will land into this kind of trouble. having your tests fail for no reason is not a pleasant experience.

I myself have used a workaround in my own code :
I call getCellMeta(x, y) for the siblings cells if the metadata retreived via getCellsMeta don't match the expected result.
but this is not perfect to rely in this kind of code to make the tests pass.

I close the issue since it's not blocking for me anymore, but I hope this will be fixed in future release.

Hi @ornoone

Thank you for the update and the workaround for others. We appreciate your feedback as well. I'll raise this issue with our developers and will let you know once we have a timeline for the fix.