-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
[Question] use with concurrent mode #426
Comments
It's important to note that However, it's interesting to know to keep us ready for concurrent mode, can you add a Codesandbox reproduction @Jack-Works? Thanks in advance. |
Oh, I thought this library is concurrent-mode-ready... Code sandbox: You may want to know contracts of working in concurrent mode correctly: facebook/react#17526 (comment) |
@Jack-Works, as ready as we can be, but we don't have any tests using the experimental branch of React. |
Hi @Thisen Thou I don't know if I'm implementing it right, there is my own example of how should things work https://codesandbox.io/s/dreamy-elion-0kzkl |
Well, it's hard to define what is CM-ready. Anyway, @Jack-Works this is nice catch. I will investigate it further. Thanks for the codesandbox too. As @Thisen noted, we don't run our tests in the experimental build, so in one aspect it's not yet supported. We do support I would like to find a proper usage, and possibly fix it. However, note that I don't think this is blocking v1 release anyway. For example, if we fix it now, it may not work in the future version of React. I'll revisit the "contracts" and check the implementation. If anyone noticed anything, it would be good to share here. |
How sync atoms trigger suspense? Does it throw a Promise? |
When render takes too much time, it will suspend. There's nothing special done in the library. That's how time slicing was working when I tested some time back. As it seems React is changing the (default?) behavior, I'd rather sit and wait until it's settled. |
@Jack-Works ReactDOM.unstable_createRoot(rootElement).render(<App />); And this is something working based on your example. If the original example should work, there might be a timing issue in jotai.
But, I'm afraid of this. Better to wait for an official doc. Please let me know if you find anything while playing with it. |
Oh I'm sorry 😂 So I tested on the behavior in the concurrent mode, doesn't look correct either. Reproduce: Type any character, for example, "abcd". Every character should have a 500ms span between them. And here is the timeline of expected output and actual output. The intermediate results are not displayed |
As jotai's setValue is mutating a ref, this is probably not possible by design. |
Yes, it is possible. There's two undocumented new API for this (redux-like) case:
Here is an example of this API (thou I don't know if it is correct): |
Hm, that was my original expectation and eventually thought uMS alone doesn't allow state branching while experimenting use-context-selector v2. Our plan is to migrate to uMS (real one), so if that solves your use case, it would be good. (Perhaps, I will update |
Let me close this for now and revisit it once React releases a new version. jotai v1 won't support CM officially, but it should work. And to my knowledge, the current behavior is correct (or best effort) at the moment. |
I try to use jotai as a concurrent-mode library but I failed to produce the result I want as I'm following https://reactjs.org/docs/concurrent-mode-patterns.html#splitting-high-and-low-priority-state
Expected:
When I type in the input, the result is updated with staled data of searchResultAtom because I'm updating it inside a
startTransition
.Actual
The App goes into the full-suspended state and displays the fallback.
isPending
never becomes true.How can I use jotai with concurrent mode correctly?
The text was updated successfully, but these errors were encountered: