Replies: 1 comment 5 replies
-
I don't understand the proposal mostly that I don't know what things like createComputed(data)
I've never looked at these libraries but this was roughly what I was thinking. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As we know,
Suspense
(originally a React component) is a Component for displaying fallbacks when a certain resource was suspended.createResource
provided an API to perform data-fetching while coordinating with the nearestSuspense
boundary to display fallback. This is ideal however there are libraries or snippets that provide a completely different strategy for data-fetching. For instance, stale-while-revalidate-based data-fetching libraries (e.g.react-query
or potentially, a Solid port of SWR) tend to show the previous data for a certain amount of time until the new data arrives, otherwise it shows the fallback. This is different fromcreateResource
which is anetwork-first
strategy.Currently to circumvent this problem we can wrap the library or the strategy into a
createResource
but that leads to unnecessary overhead or memory leak.React provided a simple way of suspending components which is for
Suspense
to catch a thrown promise. The feature is flexible enough to be called across certain contexts, but isn't direct enough to skip error boundaries (which is whatcreateResource
excels at).A proposal for this API is to provide a function (let's call it
suspend
).suspend
receives an accessor that returns a Promise result (Extra: please see #608), in which it keeps track for the entireSuspense
lifecycle.Suspense
will keep all of the results (or just track them from their respective components) and reacts to the state of the results to display the fallback indefinitely. Here's how it would look likeSince Solid's
Suspense
is optional forcreateResource
, callingsuspend
is optional too.suspend
is also useful for the third-party libraries or snippets as a means to communicate withSuspense
boundaries. It is also simple and flexible enough for users to write their own resources. This potentially allows creation of global resources (which Solid lacks currently) which allows components to share the same instance of resource.Beta Was this translation helpful? Give feedback.
All reactions