Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fake-browser): ensure nested objects are not mutated on set operation #84

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

Timeraa
Copy link
Contributor

@Timeraa Timeraa commented Dec 11, 2024

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 the set method to deep clone the items before setting them.

Improvements to storage API:

Codebase modification:

Co-authored-by: Bas van Zanten <bas.van.zanten007@gmail.com>
Copy link
Owner

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! Are there any other APIs that need this as well?

@aklinker1 aklinker1 changed the title fix(storage): ensure nested objects are not mutated on set operation fix(fake-browser): ensure nested objects are not mutated on set operation Dec 11, 2024
@Timeraa
Copy link
Contributor Author

Timeraa commented Dec 11, 2024

Good find! Are there any other APIs that need this as well?

I am not quite sure, I've so far only really used the storage of fake browser

@aklinker1
Copy link
Owner

Now that I know messaging is weird for recursive objects, should probably implement that behavior as well. Not in this PR though, I'll do it separately

@aklinker1 aklinker1 merged commit b93210f into aklinker1:main Dec 11, 2024
4 checks passed
@aklinker1
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants