Skip to content

fix: ensure $inspect works with SvelteMap and SvelteSet #12994

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

Merged
merged 9 commits into from
Aug 23, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Aug 23, 2024

Turns out that we broke $inspect at some point and it stopped working with SvelteMap and SvelteSet. This fixes that.

Copy link

changeset-bot bot commented Aug 23, 2024

🦋 Changeset detected

Latest commit: 85a73b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Conduitry
Copy link
Member

I realize it's just a handful of bytes, but are there other common use cases besides $inspect() where someone would want to have a toJSON() on these objects? If not, adding this for the sake of a dev-time-only feature bugs me.

@trueadm
Copy link
Contributor Author

trueadm commented Aug 23, 2024

I realize it's just a handful of bytes, but are there other common use cases besides $inspect() where someone would want to have a toJSON() on these objects? If not, adding this for the sake of a dev-time-only feature bugs me.

It's an odd one too. structuredClone seems to bypass all the other methods internally. I can make this DEV only though.

@Rich-Harris
Copy link
Member

With this PR, the behaviour of this code will differ between dev and prod:

$effect(() => {
  console.log('map snapshot', $state.snapshot(map));
});

We can't have that. I think we should just trigger the relevant reactivity inside clone.js by adding something like this:

if (value instanceof Map) new Map(value);
if (value instanceof Set) new Set(value);

@trueadm trueadm merged commit 21081d0 into main Aug 23, 2024
9 checks passed
@trueadm trueadm deleted the fix-inspect-map-set branch August 23, 2024 19:10
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