-
Notifications
You must be signed in to change notification settings - Fork 29
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
Shallow route change refetches data #73
Comments
Hey! I just published a new version with updated logic for detecting if query variables have changed, this should help prevent unrelated query params causing a re-render. |
Our query vars do actually change, so I don't think it will fit my usecase. We're changing the query vars so that SSR works correctly when you refresh the page. But we'd rather not fetch everything the page needs, so we're also manually refetching the affected fragment when the filter is changed. This isn't a big issue at least for now, removing the manual refetch and letting relay handle the logic does remove some code from our end. But I can still think of scenarios where this would be useful. If there's some data that's heavy to load then it would be refetched every time even if it would be enough to fetch just one fragment. If it ever becomes a big enough problem for us I can probably come up with some nice solution and make a pr :) |
Ah, we do something similar for table filters. Have you tried using |
We're using |
That's pretty much exactly what we do, but we pass the variables through to const { data, loadNext, hasNext, isLoadingNext } = usePaginationFragment<
PaginatedDataQuery,
lazyLoadedList_PaginatedData$key
>(
graphql`
fragment lazyLoadedList_PaginatedData on DataRoot
@argumentDefinitions(
cursor: { type: "String" }
count: { type: "Int", defaultValue: 50 }
filter: { type: "String" }
)
@refetchable(queryName: "PaginatedDataQuery") {
dataPages(
first: $count
after: $cursor
filter: $filter
) @connection(key: "PaginatedData_dataPages") {
totalCount
edges {
node {
...lazyLoadedList_DataRow
}
}
}
}
`,
query.dataRoot
); |
Yes that's what we do, but the source of those variables are the url and changing the url will make relay-nextjs refetch the data.
So you do update url to match the filter and also read the filter from url in |
Yep! Are you wrapping the component containing |
Yes, but we have |
Sounds great! I’d be happy to help debug on a repro project. I do think the |
Ok here's the repro: https://github.com/FINDarkside/relay-nextjs-issue-73-repro Setup is what you'd expect, |
Thank you for the repo, very easy to start debugging with this! The issue causing the double fetch is this call to |
Yes, but that's what I've been trying to explain and that's what this whole issue is about. You also told me to use |
Yea it does seem like it's running the whole page query, but the correct components are suspending, I think I just assumed that only the correct queries were being made given that UI. There may be a way to have Relay only fetch the refetchable fragment, but I'm not sure. |
No I don't think there is, it's refetching the whole query on purpose even if some of the data already exists in cache. Right now with |
+1 This feature would be very useful as it would allow us to use the query string from shallow routing to refetch data using a refetchable fragment, rather than re-rendering the entire page. I am interested in contributing if I can get some initial direction. |
When replacing route with something using shallow option, it seems like relay-nextjs still lets relay refetch the data. I'm not sure if that's intended as as far as I know, the only reason to use shallow routing would be to not trigger data fetching again. 🤔
The usecase is to avoid refetching all of the data when you use filters in our site. We store these filter options in the url (using shallow replace), but it still triggers relay to refetch all of the data.
Relevant issues, but I made a new issue since the old ones don't really explain this particular issue: #47 and #45
The text was updated successfully, but these errors were encountered: