Open hyangah opened 6 months ago
Yeah good catch, I think we should make sure that the value we store is JSON.parse(JSON.stringify...)
here:
So that the returned thing matches what you get when later asking.
Notes to self: is there more custom revive logic here:
That could alter the result once it comes back from storage? If so, can we actually provide the right value before it comes back from the renderer?
I expected Memento's
get
to recover the JSON-stringifyable object but it doesn't always.Repro: https://github.com/hyangah/vscode-extension-samples/commit/194f02e3418ec293956be62e732a43b33d483fbb
In this repro, I stored a
Date
object usingupdate
, and later attempted to retrieve the value usingget<Date>
.The first round (immediately storing the value) works as expected, except that the value doesn't match the usual ISO 8601 format (JSON.stringify returns)
Restart the extension. Now this time, the error will be thrown, because
context.globalState.get<Date>(KEY)
is not aDate
object. It's string. I am guessingget
failed to parse the persisted JSON string (ISO 8601 format), and silently returned a string object.I think this code used to work last year, but recently, we started to notice problems caused by this asymmetry. Did Memento API get changed recently?