Open lynn opened 2 years ago
That is a really good point. It seems to come from this line:
I don't remember why this was done truthfully, but if we just did JSON.stringify
on all values, it would avoid this problem
Seems to be connected to this. as we are not converting the data on first load but only on subsequent calls.
When I write
I see
x = 123456789123456800000
after refreshing the page.This is because the value is identified as being JSON when reading it back out of LocalStorage, and then
JSON.parse
turns it into a float, with loss of precision.In fact,
x
is now indeed anumber
, even though the type signature ofuseLocalStorage
promises that it isstring
. :scream:Always converting JSON has other weird consequences:
{"wow": "json injection"}
into a useLocalStorage-backed text field and break stuff!"true"
, it comes back out as a boolean valuetrue
.It might be nice to have a
useLocalStorageRaw
that only works with strings and does not "helpfully" parse strings as JSON whenever it has the opportunity.