Solid 2.0 async system design choices #2791
Unanswered
dangkyokhoang
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to ask some questions about the design choices that were made in Solid 2.0 regarding async resources.
isPendingcannot be used outside a Loading boundary for async resources? Shouldn'tisPendingbe able to be used anywhere in the tree? The below pattern is probably not uncommon - which always renders a button to refresh the resource - but doesn't work as expected:isPendingis designed to cause render errors, instead of just returningtrueorfalsewhen the resource is pending or not? The below code is expected to render the button, even ifdatafails, since nothing breaks, but actually rendersErrored.isRefreshinghas been removed in this commit 52255dc, then how do I tell whether the function increateMemois being recomputed as the result ofrefresh(resource)? I think a common use case for async createMemo is to use a separate query client / cache store likecreateMemo(() => client.query(userApi))instead of a directcreateMemo(() => fetch(userApi)). To integrate such query client with Solid's async system, I need to checkisRefreshing()(andisResetting()- if available) in thecreateMemofunction to decide whether to return cached data or to refetch. IMHO it's unlikely that one relies oncreateMemofor global state management / caching in bigger applications.The changelog mentions: "
refresh()is an action that invalidates an explicit refresh target; it should not expose ambient phase state to pure computations." Why is the function in createMemo considered pure computations? It likely interacts with external sources (that's why it's async) which means it's not pure. And "User-visible mutation or retry intent should be modeled with actions and optimistic state", but modeling refresh intents with optimistic states is probably more complex if the async resource is used in multiple places in the tree.The below pattern is common with query clients and would be more complex to implement with createOptimistic/createOptimisticStore:
The workaround for my case is to use dependency tracking between computations, to rule out known pathways that causes recomputations, and then
isRefreshing = deepStrictEqual(oldDeps, newDeps), but that's not ideal I think.It looks to me that those design choices result in somewhat... React-ish code - rules of primitives and dependency tracking. I'm new to Solid though so I might be missing something.
Beta Was this translation helpful? Give feedback.
All reactions