Code Monkey home page Code Monkey logo

Comments (10)

brunnerh avatar brunnerh commented on July 19, 2024 3

The proxy inconsistency has been fixed by #11860.
The fix has been released with [email protected]; installing that in the reproduction will cause the serialization error for every page.

That the error previously was consistent for the first page might have to do with some caching by Tanstack Query.

I outlined out how the error can be dealt with via $state.snapshot and think this issue could be closed.

from svelte.

brunnerh avatar brunnerh commented on July 19, 2024 1

E.g. here in the page:

let listInput = $derived({
-	pagination,
+	pagination: $state.snapshot(pagination),
	condition,
	orderBy: [order]
});

(There are probably other valid locations, but I think the function does currently not check deeply within the object.)

from svelte.

brunnerh avatar brunnerh commented on July 19, 2024 1

As soon as the object passes through a property, there might not be a way around that.

from svelte.

brunnerh avatar brunnerh commented on July 19, 2024

Proxies are created dynamically as needed when properties are modified in the tree, so the object structure can change internally.
If you need to make sure there are no proxies, you have to use $state.snapshot.

I would say this is neither a Svelte nor query issue.

from svelte.

frederikhors avatar frederikhors commented on July 19, 2024

@brunnerh but why I'm having issue only when pagination is {"page":1,"size":5}?

And not for page 2, 3, 4 and so on?

Can you suggest a way to fix it?

@brunnerh I tried what you suggested, but it's the same. I updated the question too.

from svelte.

brunnerh avatar brunnerh commented on July 19, 2024

It starts out with a proxy because the object is passed around through props.
The reassignment then removes this again (there might actually be a bug here if it does not get added back on modification - #11859).

There are various ways to avoid the issue, like not binding objects (<Pagination bind:pagination />) but rather use primitives (<Pagination bind:page bind:size />) or use events instead of bindings.

But if you have objects that are involved with state, the only safe thing to do is using $state.snapshot or manually creating a plain object.

from svelte.

frederikhors avatar frederikhors commented on July 19, 2024

But if you have objects that are involved with state, the only safe thing to do is using $state.snapshot or manually creating a plain object.

Can I ask you how?

from svelte.

frederikhors avatar frederikhors commented on July 19, 2024

@brunnerh even if I use this:

<Pagination {pagination} onchange={(value) => pagination = value} />

The first one is a Proxy!

from svelte.

paoloricciuti avatar paoloricciuti commented on July 19, 2024

E.g. here in the page:

let listInput = $derived({
-	pagination,
+	pagination: $state.snapshot(pagination),
	condition,
	orderBy: [order]
});

(There are probably other valid locations, but I think the function does currently not check deeply within the object.)

This is actually working for me

https://stackblitz.com/edit/sveltejs-kit-template-default-v4emiu?file=src%2Froutes%2F%2Bpage.svelte

Consider that sometimes stackblitz doesn't recompute.

That said why are you getting this from the props of a +page.svelte? You can't receive other props than data, form and children...i think the fact that is a proxy is because is the default value of a prop

from svelte.

frederikhors avatar frederikhors commented on July 19, 2024
pagination: $state.snapshot(pagination)

Yeah. This works.

why are you getting this from the props of a +page.svelte?

Just an example. My real code is more complex.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.