-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Feedback for React query preloading feature #11519
Comments
Really excited for this change and what it means for integration with routing frameworks! Its awesome to see how much Apollo Client has been continuing to grow and improve |
@WonderPanda thanks so much for the kind comments! |
This feature is really great. Thank you very much for the work you're doing. I can't wait for the version 3.10.0. |
@SteveGT96 thanks so much! |
This is quite cool, thank you! Is the |
Adding this feature to the React Apollo Client would simplify unnecessary conditional rendering logic in React, making development more efficient and code easier to manage. |
@benrbrook great question! This won't work with import { MockLink } from '@apollo/client/testing';
const mocks = [...] // The same structure you pass to MockedProvider
// Use `MockLink` directly
const link = new MockLink(mocks);
const client = new ApolloClient({
cache: new InMemoryCache(),
link
});
const preloadQuery = createQueryPreloader(client);
// This preloadQuery function will use the mocks in `MockLink` instead We should have something in the docs about this though. Thanks for calling this out! Edit: I've opened #11733 to track this. |
Hey all 👋 We've just released v3.10 that stabilizes this API. As such, I'm going to go ahead and close out this issue. Thanks so much for all those that tried the API and provided feedback! I'm hoping you enjoy the new APIs! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
@jerelmiller sorry for posting in closed issue but this seems like a good place for asking some questions I like the preloadQuery API but a couple of things bothers me:
Looks like the most of my questions become obsolete if I just use Thanks in advance for any tips |
One more thing I noticed: When I use |
Hey @misha-erm for the strict mode issue, could you try the snapshot release from #11821 and see if it fixes your issue?
If not, would you be open to creating a new issue with a reproduction so we can track this? As for your other questions: It looks like your first question was answered in the forum, so I'll leave that there.
We currently don't support polling with Suspense. We've discussed this a couple times as a team and we're all in agreement that we'd like to avoid it for now. Polling gets a bit strange with Suspense and React transitions and we think there could be a lot of confusion on how it should work. As you mentioned, you should be able to use a combination of
Just a note: That being said, we've heard the sentiment about polling with Suspense, so we'll keep watch for the demand here. If we get a lot of asks for it, its certainly something we can explore. Hope this helps! |
@jerelmiller just checked the patch, seems to work fine 👍🏻 However I still see some random cancellations of subscriptions but they are rare and I see them without StrictMode as well. Maybe will dig deeper later and create a new issue if needed. Thank you BTW, I decided to opt-out from strict mode after spending a day trying to understand the strange behaviour of our queries in prod env comparing to dev. Turned out I was facing this bug #11772 but it was not reproducible with StrictMode ))) About the preload stuff:: For most of my cases |
If you're willing to go more in detail, I'd be curious about this. How would this differ from how you'd do this with e.g.
Short answer is: its not quite as simple as that 😆. Suspense is not the only difference, but its one of the big ones. You are right that you do get some of the same benefits for network requests, but I'll add the caveat that it requires a bit more careful management on your end to ensure you get this benefit. Its possible to accidentally introduce more than one network request with this approach since these queries aren't connected to each other. This problem compounds a bit depending on how you're using Let's take an example to show you what I mean. const loader = async ({ params }) => {
return {
post: await client.query({ query: GET_POST, variables: { id: params.postId } })
}
}
const RouteComponent = () => {
const { postId } = useParams()
const { data, loading } = useQuery(GET_POST, { variables: { id: postId } });
// ...
} There are a couple things to note here: The obvious one is that you're having to pass the query and You'll also notice that this example doesn't use data from your One of the big things here though is the If you prefer to transition the page immediately, you'd need to remove that Hopefully you're seeing how this makes the process a bit more complicated. If you find something that works for you, by all means, go for it. We can't stop you from using it. Just wanted to communicate the risks here so you can make an informed decision on how best to accomplish what you're after. |
thank you for such a detailed answer 🙇🏻 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Starting with Apollo Client 3.9.0, you can begin preloading queries outside React using the
createQueryPreloader
/preloadQuery
APIs. We've marked these as experimental for this release to allow room for feedback and changes before we stabilize this API in 3.10.0.If you would like to provide feedback or suggestions for improvement, please drop a comment below!
The text was updated successfully, but these errors were encountered: