Too many requests when rendered conditionally #1671
Replies: 3 comments
-
There will be a new selection cache covering conditional renders, I am experimenting with a few extreme cases to make sure it neither over-fetches nor under-fetches.
Does it make sense? |
Beta Was this translation helpful? Give feedback.
-
Hey y'all — completely uninformed speculation here, but I wanted to sketch out a possible solution. From your description, it sounds like you are not targeting initial renders. Is that so? (I don't think a selection cache is a great solution for initial renders of pages, especially when the page is customized to the user (e.g. /user/:id). IMO, that is probably the most important time to avoid waterfalls.) Okay, here goes. Feel free to tell me I'm wrong. Things I think are true:
Proposed solutionOkay, so the gist is that I think that any conditional branch that you want to be sure gets exercised has to go through a hook that qgty provides. This makes the condition visible to gqty, and means that gqty can re-render the component and exercise all branches you care about. (It may not need to be a hook! Maybe a regular function works.) ExampleAn example that doesn't work, because
But it can be made to work as follows:
Now, when gqty renders the component, it notices that we're calling Additional thoughts:
|
Beta Was this translation helpful? Give feedback.
-
@rbalicki2 tl;dr You may pass The issue boils down to initial developments where fields may change rapidly, or not known beforehand, that's where GQty focus the most. At the moment it means for each conditional code path, there will be 2 renders (1 with suspense) and 1 fetch. With the When using without |
Beta Was this translation helpful? Give feedback.
-
When a component with query is rendered conditionally, gqty makes too many (in my case 5) requests
query.tsx
test.tsx
Beta Was this translation helpful? Give feedback.
All reactions