-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
add ability to warn when suspense queries aren't prefetched #8309
base: main
Are you sure you want to change the base?
add ability to warn when suspense queries aren't prefetched #8309
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 0e5b86c. 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. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8309 +/- ##
===========================================
+ Coverage 45.96% 62.67% +16.71%
===========================================
Files 199 135 -64
Lines 7501 4799 -2702
Branches 1717 1348 -369
===========================================
- Hits 3448 3008 -440
+ Misses 3676 1549 -2127
+ Partials 377 242 -135
|
* Use this if you intend to only consume prefetched queries. | ||
* Defaults to `false`. | ||
*/ | ||
warnOnServerFetches?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bike shedding: discussed with co-workers, something like strictPrefetch
/strictPrefetches
? Happy with whatever the consensus is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also consider different levels, so for example strict
might lead to a runtime exception when compared to passing a warn
value to simply log it 🤔
- given @TkDodo's recent talk, this should probably also accept a callback that gets the query(?) and not just a static boolean flag
- warning log might be too specific, would it be better for this to be a function and allow the developer to control what should happen? Perhaps they want to log more/less info about the query to help track down the query that's missing a prefetch
I do like the callback approach more though, we could add an option called onPrefetchMiss
or something along those lines.
This would give us more control over the outcome, e.g. could add observability, warning, throw an exception, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like the callback approach more though, we could add an option called
onPrefetchMiss or something along those lines.
This would give us more control over the outcome, e.g. could add observability, > warning, throw an exception, etc.
yea definetely see this useful for much more than just warning for un-prefetched queries. would love @TkDodo's thoughts on what API he prefers
When using the promise-rsc-hydration thingy we aim to prefetch all queries in the RSCs and just consume the streamed promises in our components.
This can be a bit fragile since forgetting to prefetch may not be obvious to find. This PR adds a new option that, when enabled, will log at warning level when
useSuspenseQuery
is called on a new query that's not already observed.as with all options, this can be set globally when constructing the QueryClient and overridden locally cause you may have queries
Questions
usePrefetchQuery -> useSuspenseQuery
pattern in a SPA as well