-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: unstate object in Svelte 5 dev mode #12095
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@sveltejs/kit": patch | ||
| --- | ||
|
|
||
| fix: unstate object in Svelte 5 dev mode before checking serializability |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { BROWSER, DEV } from 'esm-env'; | ||
| import { onMount, tick } from 'svelte'; | ||
| import * as svelte from 'svelte'; | ||
| import { | ||
| add_data_suffix, | ||
| decode_params, | ||
|
|
@@ -45,6 +45,9 @@ import { HttpError, Redirect, SvelteKitError } from '../control.js'; | |
| import { INVALIDATED_PARAM, TRAILING_SLASH_PARAM, validate_depends } from '../shared.js'; | ||
| import { get_message, get_status } from '../../utils/error.js'; | ||
| import { writable } from 'svelte/store'; | ||
| import { VERSION } from 'svelte/compiler'; | ||
|
Comment on lines
47
to
+48
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd put these two lines up with the other svelte import just to keep things a little organized |
||
|
|
||
| const is_svelte_5 = +VERSION.split('.')[0] >= 5; | ||
|
|
||
| let errored = false; | ||
|
|
||
|
|
@@ -1413,7 +1416,7 @@ async function navigate({ | |
| const { activeElement } = document; | ||
|
|
||
| // need to render the DOM before we can scroll to the rendered elements and do focus management | ||
| await tick(); | ||
| await svelte.tick(); | ||
|
|
||
| // we reset scroll before dealing with focus, to avoid a flash of unscrolled content | ||
| const scroll = popped ? popped.scroll : noscroll ? scroll_state() : null; | ||
|
|
@@ -1627,7 +1630,7 @@ function handle_error(error, event) { | |
| * @param {T} callback | ||
| */ | ||
| function add_navigation_callback(callbacks, callback) { | ||
| onMount(() => { | ||
| svelte.onMount(() => { | ||
| callbacks.push(callback); | ||
|
|
||
| return () => { | ||
|
|
@@ -1861,7 +1864,12 @@ export function pushState(url, state) { | |
| if (DEV) { | ||
| try { | ||
| // use `devalue.stringify` as a convenient way to ensure we exclude values that can't be properly rehydrated, such as custom class instances | ||
| devalue.stringify(state); | ||
| devalue.stringify( | ||
| is_svelte_5 | ||
| ? // @ts-expect-error This package has a dev dependency on Svelte 4, but `svelte.unstate` only exists in Svelte 5 | ||
| svelte.unstate(state) | ||
| : state | ||
| ); | ||
| } catch (error) { | ||
| // @ts-expect-error | ||
| throw new Error(`Could not serialize state${error.path}`); | ||
|
|
@@ -1901,7 +1909,12 @@ export function replaceState(url, state) { | |
| if (DEV) { | ||
| try { | ||
| // use `devalue.stringify` as a convenient way to ensure we exclude values that can't be properly rehydrated, such as custom class instances | ||
| devalue.stringify(state); | ||
| devalue.stringify( | ||
| is_svelte_5 | ||
| ? // @ts-expect-error | ||
| svelte.unstate(state) | ||
| : state | ||
| ); | ||
| } catch (error) { | ||
| // @ts-expect-error | ||
| throw new Error(`Could not serialize state${error.path}`); | ||
|
|
@@ -1955,7 +1968,7 @@ export async function applyAction(result) { | |
|
|
||
| root.$set(navigation_result.props); | ||
|
|
||
| tick().then(reset_focus); | ||
| svelte.tick().then(reset_focus); | ||
| } | ||
| } else if (result.type === 'redirect') { | ||
| _goto(result.location, { invalidateAll: true }, 0); | ||
|
|
@@ -1969,7 +1982,7 @@ export async function applyAction(result) { | |
| }); | ||
|
|
||
| // ...so that setting the `form` prop takes effect and isn't ignored | ||
| await tick(); | ||
| await svelte.tick(); | ||
| root.$set({ form: result.data }); | ||
|
|
||
| if (result.type === 'success') { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.