Skip to content
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

RFC: Support next/link prefetched data in next-urql #1567

Closed
yoshiwarab opened this issue Apr 26, 2021 · 1 comment · Fixed by #1602
Closed

RFC: Support next/link prefetched data in next-urql #1567

yoshiwarab opened this issue Apr 26, 2021 · 1 comment · Fixed by #1602
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@yoshiwarab
Copy link

Summary

The Link component from next/link has prefetch turned on by default. For pages using static generation, this includes preloaded JSON data. Currently pages wrapped by withUrql ignore this data on client side transitions. I propose that support is added to take advantage of the prefetched SSG data.

Proposed Solution

Currently if an ssr exchange already exists, withUrql ignores pageProps.urqlState so it doesn't get the prefetched data on a client side transition. By updating this https://github.com/FormidableLabs/urql/blob/b6890ba1b0c9fa9e99301338555ea10d602cee22/packages/next-urql/src/with-urql-client.ts#L55-L58 to restore data to an existing ssr exchange it would be possible to hydrate the client with the prefetched data.
} else if (ssr) { ssr.restoreData(urqlState) }

Also, thank you for the amazing library :)! Hopefully this wouldn't break something else!

@yoshiwarab yoshiwarab added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Apr 26, 2021
@kitten
Copy link
Member

kitten commented Apr 28, 2021

I think we'll need to test this; Personally, I don't have a huge overview of next-urql but @JoviDeCroock may know whether this will "just work". I don't think we've ever tested the prefetch behaviour, so once we see how it works we can probably test it properly. But in theory this does check out for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants