RevereCRE / relay-nextjs

⚡️ Relay integration for Next.js apps
https://reverecre.github.io/relay-nextjs/
MIT License
251 stars 30 forks source link

Shallow routing support #47

Closed FINDarkside closed 2 years ago

FINDarkside commented 2 years ago

This has been discussed in #41 but I think I will need shallow routing even though you said it's not supported. Not really asking you to make it, I'm willing to make a PR if you think it's ok idea and I can come up with some acceptable solution. Right now I'm thinking of just making option for always rendering suspense (even server side), since React 18 supports server-side suspense. Not sure if that would solve all the issues with shallow routing.

The usecase is following: We have infinite feed in our page and want to be able to return to the same position when user visits other page. Obvious solution to this is storing the necessary info in the url, but we can't really do that properly without shallow routing. If we just put the starting cursor + count and let relay fetch the whole query again, it'll mean that we will constantly refetch all of the content in the feed that has already been loaded instead of just the next x items.

rrdelaney commented 2 years ago

Yea I should rephrase how we support shallow routing: it's totally supported for in-page navigation such as changing query params, but unsupported for navigating to a new page that is using relay-nextjs. Does setting the store to only use the cache work for your use-case?

FINDarkside commented 2 years ago

Hey I think I ran into some issues with queries being released too early or something and assumed it was because of the conversation I linked to in the opener. I'll look more into this in the coming weeks.

Does setting the store to only use the cache work for your use-case?

No, we want to load the next x items in the feed and not load the ones that are already loaded. But we are indeed only doing shallow routing to do in-page navigation so I guess it should work. I'll need to re-check.

FINDarkside commented 2 years ago

Ok finally tested this out again and everything works just fine. Not sure what the issue was last time, probably not related to relay-nextjs so I'll close this.