react-spreadsheet icon indicating copy to clipboard operation
react-spreadsheet copied to clipboard

Improve formula updating

Open iddan opened this issue 4 years ago • 25 comments

Formula updating is buggy with the latest versions of React

iddan avatar Mar 26 '20 18:03 iddan

@iddan any idea what the issue is?

I have the case where values are not getting updated unless you focus on that cell. Is this issue related to that?

meetmangukiya avatar Sep 11 '20 10:09 meetmangukiya

I believe it is.

iddan avatar Sep 15 '20 10:09 iddan

I tried to dig into it. Wasn't able to figure out the problem. However, I noticed that this is not buggy in the website version which makes me think maybe it is related to https://github.com/iddan/react-spreadsheet/issues/70. Didn't find the source for the gh-pages so couldn't verify the version of react that was used on it.

meetmangukiya avatar Sep 15 '20 23:09 meetmangukiya

Some one know if have a version that don't occur this bug? I'm using 0.4.48

mgotze avatar Sep 16 '20 04:09 mgotze

I looked into it further. React version used on https://iddan.github.io/react-spreadsheet/ is v16.8.6 so in fact it is not related to https://github.com/iddan/react-spreadsheet/issues/70. So I am not sure what gives. Maybe it is the react-spreadsheet version and this bug creeped in later and the website is using earlier version.

meetmangukiya avatar Sep 16 '20 05:09 meetmangukiya

The gh-pages branch's latest commit is on May 7, 2019. So it is probably using react-spreadsheet v0.4.32

meetmangukiya avatar Sep 16 '20 05:09 meetmangukiya

Thanks for the information @meetmangukiya I tried on v0.4.32, but the bug continues, I noticed that when my table starts with a formula the bug occurs, but if the formula is reissued the bug does not occur. Maybe that's why it doesn't happen on the site

mgotze avatar Sep 16 '20 06:09 mgotze

@mgotze i've raised a fix, you can add that version to your app and help test if it got fixed

meetmangukiya avatar Sep 16 '20 06:09 meetmangukiya

Thats nice :D what version I can use? it's a v0.4.48?

mgotze avatar Sep 16 '20 06:09 mgotze

yarn add @flamy-dev/react-spreadsheet

meetmangukiya avatar Sep 16 '20 06:09 meetmangukiya

Oh, thanks!

mgotze avatar Sep 16 '20 06:09 mgotze

@meetmangukiya here for me the same bug happens whit this behavor when table starts with a formula the bug occurs, but if the formula is edited the bug does not occur.

mgotze avatar Sep 16 '20 07:09 mgotze

Not sure what you mean. Can you give an example, or what your data is?

meetmangukiya avatar Sep 16 '20 07:09 meetmangukiya

@meetmangukiya
For example my table starts with this data

[{value: ''}, {value: ''}], [({value: ''}, {value: '=A1+B1'})],

then the bug occurs, but if I edit the formula after this directly on table, the bug doesn't happen anymore

mgotze avatar Sep 16 '20 07:09 mgotze

try initializing with 0(not as a string) maybe?

meetmangukiya avatar Sep 16 '20 07:09 meetmangukiya

Same problem [ [{ value: 0 }, { value: 0 }], [{ value: 0 }, { value: '=A1+B1' }], ]

@meetmangukiya example: https://ibb.co/PCHxNj5

mgotze avatar Sep 16 '20 07:09 mgotze

Yeah I think this has to do with bindings and the fact that the initial state of bindings is not set. They get set only on edit. @iddan can you change the initialization to set the initial bindings? I am a bit hazy as to how bindings are working. But pretty sure it has to do with the fact the initialization of state does not set bindings and they only get set on editing of cells; for that cell.

meetmangukiya avatar Sep 16 '20 08:09 meetmangukiya

Hey @meetmangukiya and @mgotze. Thank you for using React Spreadsheet. At the moment I'm really busy so I can't get the time to update the code but I would love to review a PR.

iddan avatar Sep 16 '20 08:09 iddan

Hi @iddan It's awesome to use react-spreadsheet, too bad I don't have enough knowledge to make this correction, I really needed

mgotze avatar Sep 16 '20 09:09 mgotze

I wont be fixing the bindings anytime soon. But the PR I raised fixes one bug I guess.

meetmangukiya avatar Sep 16 '20 09:09 meetmangukiya

@iddan, so no idea when this bug will ne fixed?

mgotze avatar Sep 16 '20 13:09 mgotze

I might get to it in a week. Right now I'm really busy.

iddan avatar Sep 16 '20 14:09 iddan

Wow that optimistic, sorry 😅 . Last night I came up with a strategy that I think would make formula updating work as expected: Every time a cell renders it will update a matrix in the state of computed values and use the computed values of other cells to compute its value. That way if a cell updates it will trigger a re-render for all of its dependencies without keeping a graph of dependencies in the state.

iddan avatar Sep 20 '21 21:09 iddan

Working on some other direction here: #214

iddan avatar Apr 08 '22 16:04 iddan

Giving it a second try in #63

iddan avatar Aug 07 '22 07:08 iddan

This is solved with [email protected]

iddan avatar Apr 22 '23 10:04 iddan