Code Monkey home page Code Monkey logo

Comments (5)

crimsonhawk47 avatar crimsonhawk47 commented on August 20, 2024

To narrow this down more, if you simplify the code to do NOTHING.

const result = produce(appState, (draft) => {
            console.log("woah")
        });

You will still get an error

'getOwnPropertyDescriptor' on proxy: trap returned descriptor for property 'todos' that is incompatible with the existing property in the proxy target
    at Function.entries (<anonymous>)
    at freeze (immer.js?v=7cbabef2:168:12)
    at maybeFreeze (immer.js?v=7cbabef2:333:5)
    at finalize (immer.js?v=7cbabef2:277:5)
    at processResult (immer.js?v=7cbabef2:255:14)
    at Immer2.produce (immer.js?v=7cbabef2:551:16)
    at HTMLButtonElement.onClick (+page.svelte:23:24)
    at next (chunk-33KSVKAN.js?v=7cbabef2:346:14)
    at chunk-33KSVKAN.js?v=7cbabef2:358:25
    at yield_updates (chunk-7ZZEPC7R.js?v=7cbabef2:1868:12)

This does not happen if you remove $state and make it a raw object

from svelte.

crimsonhawk47 avatar crimsonhawk47 commented on August 20, 2024

Looks like the solution is to use $state.snapshot per the docs.

const result = produce($state.snapshot(appState), (draft) => {
    console.log("woah")
});

You can close this unless action needs to be taken here

from svelte.

dummdidumm avatar dummdidumm commented on August 20, 2024

Since immer is designed to handle immutable state, another possibility would be $state.frozen, but it likely wouldn't work when trying to mutate top level properties of the object because it's frozen. Mhm..

from svelte.

brunnerh avatar brunnerh commented on August 20, 2024

It works with frozen, the whole point of immer is to never modify objects at all but to replace them if anything changes.

from svelte.

dummdidumm avatar dummdidumm commented on August 20, 2024

Oh right, they're doing a proxy themselves etc.

Yeah, $state.frozen is the way then - closing since there are ways to solve this.

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.