-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: use devalue for pushState/replaceState #14129
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: df5d01b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
e47baa8
to
ac02814
Compare
I don't think we can do this. Today, if you try and do something like this... <script>
import { page } from '$app/state';
import { pushState } from '$app/navigation';
</script>
<section>
<button
onclick={() => {
let object = $state({ count: 0 });
pushState('/', { object });
}}
>
push state
</button>
{#if page.state?.object}
<p>{page.state.object.count}</p>
<button onclick={() => (page.state.object.count += 1)}>
increment page.state.object.count
</button>
{/if}
</section> ...SvelteKit will yell at you, because you can't serialize a proxy. With this PR, if you click the first button, |
(Technically it's the browser that yells at me if I give it a proxy, devalue will happily serialize it) Would it be acceptable to In dev we can also add a warning that reactivity will be lost for history states if that makes the behavior less surprising |
Hi!
Closes #14128:
pushState
/replaceState
now use devalue+transport to serialize custom objectsI kept it simple, not sure if the idea will be accepted
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits