json-edit-react icon indicating copy to clipboard operation
json-edit-react copied to clipboard

Number are not reset when exiting the text box

Open BoBer78 opened this issue 9 months ago • 6 comments

Describe the bug When editing an number, it does not reset when clicking elsewhere. The internal state is unchanged but what is displayed is.

Expected behavior See below screen recording. First behavior with numbers is incorrect. Second with strings is correct.

Screenshots https://github.com/user-attachments/assets/4afc8f9b-03e1-49b6-a174-5c4efa3a7295

Online demo The screen recording was made using the live demo.

Thanks for the great package by the way, very intuitive and super useful !

BoBer78 avatar Apr 07 '25 07:04 BoBer78

Thanks for spotting this inconsistency, I'll fix ASAP!

CarlosNZ avatar Apr 07 '25 08:04 CarlosNZ

Should be fixed now in v1.25.1.

Thanks for reporting -- it was literally a one word error (just referring to the wrong variable), but it could have gone unnoticed for a long time!

CarlosNZ avatar Apr 09 '25 00:04 CarlosNZ

Sorry to bother again, it seems like the issue is still unresolved. I tried locally and in the live demo on version v1.25.1.

Just to be clear, here are the steps to recreate :

  • click on a number (for example the 99 in the demo)
  • Enter a random value (valid one)
  • Click on another field.

--> This will leave the number you entered shown on screen. It does not trigger validation nor sets the internal state. All the other field types (for example strings) are reset to their old value when you repeat the same steps.

This is not an urgent fix for us, just letting you know that the bug is still there.

BoBer78 avatar Apr 10 '25 07:04 BoBer78

Oh, that's annoying. At first I was unable to reproduce it on the demo, but I did it a few more times and eventually it happened. Damn, must be a race condition somewhere -- I'll have a closer look into it.

CarlosNZ avatar Apr 10 '25 10:04 CarlosNZ

@BoBer78 -- hey, just wondering if you're still seeing this in the latest version?

CarlosNZ avatar May 07 '25 05:05 CarlosNZ

Yes I still see the issue (locally and in in the demo), I will update this comment tomorrow with some video.

Update :

Here is what I get when using the live demo : https://github.com/user-attachments/assets/692d1c61-a94d-4b1e-8032-3b74712d9fd7

It might be intended behavior, but if I am editing a field and then click on another one, it changes without triggering the validation, nor setting the react state. If I click on the validate button after that, it will work. Before this was the case only with the numbers, now the strings have the same comportment.

The issue is that when I use your package in our app : https://github.com/user-attachments/assets/0f6a8f05-4544-4a10-9661-04e024d8ff3c

You can see that I changed some important value for a simulation. In particular the seed, time step and total time. When I accept, this is what is send to the server :

{'me_model_id': 
 [...] 
'conditions__max_time': 100, 
'conditions__time_step': 0.05, 
'conditions__seed': 100}

The values have not been changed, what is displayed on json viewer is not matching was is saved in the React state. For reference I am currently on version [email protected], and in my code I am using to manage the arguments state:

onUpdate={({ newData }) => {
                        const result = scsPostSchema.safeParse(newData);
                        if (!result.success) {
                          [...]
                         }
                        handleArgsChange(result.data);
                      }}
setData={(data: JsonData) => handleArgsChange(data)}

Everything works fine if I use the button to validate. As stated before, maybe this is the way that the package is intended to work.

BoBer78 avatar May 13 '25 14:05 BoBer78