fix(fake-browser): ensure nested objects are not mutated on set operation #84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a nasty bug that I came across when writing storage tests inside of wxt and I couldn't figure out why at the time and now my friend @Bas950 came across the same issue and it turns out that the
fakebrowser
package doesn't remove the references when updating the object.I tried using
structuredClone
but it didn't quite fix the issue in some deeply nested objects / arrays.Idk if you remember this @aklinker1 https://discord.com/channels/1212416027611365476/1224505556346212515/1308235414582071358 but this is the fix of that issue.
The bun lock probably got updated because I have the latest version of it.
This pull request includes changes to the
fake-browser
package to improve the handling of nested objects in the storage API. The most important changes include adding a new test case to ensure nested objects are not mutated and modifying theset
method to deep clone the items before setting them.Improvements to storage API:
packages/fake-browser/src/apis/storage.test.ts
: Added a test case to ensure that setting a nested object does not mutate the original object.Codebase modification:
packages/fake-browser/src/apis/storage.ts
: Modified theset
method indefineStorageArea
to deep clone the items usingJSON.parse(JSON.stringify(items))
before setting them.