jotaijs / jotai-scope

MIT License
60 stars 4 forks source link

Atoms not working with Jotai v2.9 (new store implementation) #41

Closed rothsandro closed 3 months ago

rothsandro commented 3 months ago

Jotai Scope doesn't work with Jotai v2.9 (which introduced the new store implementation). A non-scoped atom used inside a Jotai Scope Provider receives the default value, not the latest value.

Reproduction

Repro: https://stackblitz.com/edit/vitejs-vite-8ilg8j?file=src%2FApp.tsx&terminal=dev

The first component is rendered inside a scope provider, the other two components are rendered outside. All of them use the same non-scoped atom.

If you enter a value into the first field, all three inputs should have the same value and display the same value. But only the 2nd + 3rd components render the latest value, the first component doesn't render a value.

dmaskasky commented 3 months ago

Acknowledged. This issue will be resolved with the rewrite I'm working on based off of the new jotai store api https://github.com/pmndrs/jotai/pull/2652.

dmaskasky commented 3 months ago

Ok, this is a weird one. I confirmed this is indeed a bug, however if I add the exact same code locally to codesandbox it works?

The only difference is import { Scope Provider } from 'jotai-scope' vs import { ScopeProvider } from './jotai-scope'.

I added tests to try to reproduce but they pass. https://github.com/jotaijs/jotai-scope/pull/43

I'm so confused.

https://codesandbox.io/p/sandbox/atom-with-observable-infinite-mount-bug-fix-forked-253y84

dmaskasky commented 3 months ago

Well, this is embarrassing...

Back in May I did a full rewrite of jotai-scope to support a whole slew of edge-cases including support derived atoms. It was a full ground-up rewrite of jotai-scope. I also added a ton of tests to support all conceivable edge-cases. But it NEVER GOT DEPLOYED 😱 ...

This is why jotai-scope main works but jotai-scope@0.6.0 does not.

I'll deploy now, and this will solve this issue.

dmaskasky commented 3 months ago

v0.7.0 is released and is working. 🥳 https://stackblitz.com/edit/vitejs-vite-6qcwnz?file=package.json

rothsandro commented 3 months ago

Yeah, thanks a lot 🙏