Skip to content
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

Remove reference to, or even warn about, using immer and binding with aurelia-store #478

Open
NightWulfe opened this issue Apr 26, 2020 · 1 comment

Comments

@NightWulfe
Copy link

I'm submitting a bug report

  • Library Version:
    aurelia-framework 1.3.1
    aurelia-store 1.6.0
    immer 6.0.3

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    13.12.0

  • NPM Version:
    6.14.4

  • JSPM OR Webpack AND Version
    Webpack 4.42.1

  • Browser:
    Firefox 75.0

  • Language:
    TypeScript 3.8.3

Current behavior:
The Aurelia documentation guide for "Managing App State" demonstrates binding state properties directly in templates. The documentation then indicates that readers should review the Immer library to assist with ensuring their state remains immutable, implying that Immer is compatible with Aurelia when used in this way.

However, actually attempting to use Immer with Aurelia while binding directly to the store state results in the error "Immer drafts cannot have computed properties". I believe this is due to data-binding modifying the state objects with getters/setters for observing the values. The error means that Immer cannot reliably clone the object because it contains functions/getters/setters/computed properties.

More information about this error can be found here:
immerjs/immer#392
immerjs/immer#317
Possibly immerjs/immer#202

You can see this error in action here (Click the button after the app loads):
https://codesandbox.io/s/aurelia-javascript-sandbox-21zw1?file=/src/app.js

Expected/desired behavior:
I spent a few hours researching and testing aurelia-store with Immer and aurelia-store, thinking I was doing something wrong. Eventually I gave up and asked about it in discord to find out it was a known issue.

IMO the documentation needs to be updated to remove mentioning Immer, or document an alternate approach that allows the use of Immer, such as not binding to the store state directly. Though I found even that can be tricky, as if you're not careful to properly copy your component state from the store state, aurelia still manages to bind into the store state and it's very difficult to track down where this is happening.

I also acknowledge I'm fairly new to Aurelia, so if I'm doing something wrong, please let me know.

@NightWulfe
Copy link
Author

NightWulfe commented Apr 26, 2020

I just found reference to this same issue on Discourse, so I thought I'd link it here.

https://discourse.aurelia.io/t/aurelia-store-immerjs-and-objects/2601/30

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

No branches or pull requests

1 participant