-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(solid-query): respect suspense: false #6415
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d9ad21e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d9e4de1:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #6415 +/- ##
==========================================
+ Coverage 87.92% 88.34% +0.42%
==========================================
Files 87 75 -12
Lines 2931 2592 -339
Branches 804 684 -120
==========================================
- Hits 2577 2290 -287
+ Misses 295 257 -38
+ Partials 59 45 -14 ☔ View full report in Codecov by Sentry. |
|
Nx shows that tests failed for react-query, unsure why. |
|
I'm not sure this is what we want. We've moved away from the suspense boolean flag in react, and as far as I remember talking to @ardeora, the suspense flag is unnecessary in solid. I think we should rather remove it completely on type level rather than starting to respect its value ... |
|
You are right. Another solution I can think of is to expose the |
|
yeah in react, we have separate hooks to trigger suspense ( But the |
|
Actually, I do not think
// In React:
function Comp() {
const query = useSuspenseQuery(); // <-- suspense triggers here
return <div>{query.data}</div>;
}
function Parent() {
return (
<Suspense fallback='No data'> // <-- boundary has to be defined in Parent
<Comp />
</Suspense>
);
}
// In Solid:
function Comp() {
const query = useQuery();
return (
<div>
<Suspense fallback='No data'> // <-- boundary can be defined at any point
{query.data} // <-- suspense triggers here
</Suspense>
</div>
);
}I think the adding a function Comp() {
const query = useQuery();
return (
<div>
{query.latest.isSuccess ? query.latest.data : 'No data'} // <-- suspense never triggered
</div>
);
}If this sounds good to you and @ardeora then I will just open another PR for it. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d9e4de1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Yeah, they work differently, and the query types would still have to have |
I would really like this. We've patched query locally to have const latest = createMemo(() => {
const val = queryResource.latest?.data
return val !== undefined ? val : state.data
})
const handler = {
get(
target: QueryObserverResult<TData, TError>,
prop: keyof QueryObserverResult<TData, TError> & "latest",
): any {
if (prop === 'latest') return latest()
const val = queryResource()?.[prop]
return val !== undefined ? val : Reflect.get(target, prop)
},
}It could be changed to include the whole |
|
Thinking on this more, I wonder if another approach would be for only |
This seems like the right balance. @ardeora would love to have your seal of approval here. |
|
Hello @aadito123 ! Sorry for the late and absolutely unacceptable lack of response here. I wanted to get some of the improvements in place and rework the internals to have a better view of how we can respect the There are a few things that making this work with
const query = createQuery(() => ({...}))
return (
return (
<ErrorBoundary fallback={'Will be caught here when query errors'}>
<p>{query.data}</p>
</ErrorBoundary>
)
)I love this and honestly it makes writing components more intuitive but if someone sets
So what's the correct API design here? I am open to feedback here but I feel we can adopt the react query approach. With v5 react-query introduced a separate In SolidJS, Suspense always had first class support and is the recommended way to fetch data and perform async operations. So for Solid Query I feel like having a separate API for This way there would be a clear distinction of what features are available with Non Suspense queries and how they differ from traditional queries. They would ideally be used client only and error boundaries would need to be higher up in the tree. What do you think? I would be happy to merge these new APIs if you feel they make sense. Tagging @marbemac and @Brendonovich (apologies for the weekend spam) too for their feedback |
|
Now that Let's just remove the |
No worries! Agree with your point. I am not sure about the SSR part since I would assume that without suspense, the server just won't perform the query, and just send down the loading content. Regardless, #7272 only triggers suspense for On that note, I'll close this PR. |
|
@ardeora I think your recent changes address all the changes I'd make to suspense, last thing I'd like to see is a |
|
|
|
@aadito123 Ah yeah good point, I forgot ts query is SWR by default as opposed to |
As of now, the default in solid-query is to suspend when accessing inside a suspense boundary. This may not always be ideal, hence the
suspenseoption is provided. However, that option was not respected. Fixed now.Default behaviour is still to suspend, but now with
suspense: falseit won't. Added relevant test case and updated comment to reflect the difference between react and solid's suspense behaviour.#5657 This issue seems to have been a blocker for other users.