-
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
Add serverSidePostQuery hook to access query data + NextContext during SSR #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thank you so much for the PR! I'm going to be out a lot of this week, so will get to it when I can.
@@ -175,6 +183,11 @@ async function getServerInitialProps<Props extends WiredProps, ServerSideProps>( | |||
|
|||
await ensureQueryFlushed(preloadedQuery); | |||
|
|||
if (serverSidePostQuery) { | |||
const queryResult = await preloadedQuery.source?.toPromise(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this cause a double network request? I'm not sure if the observables returned from Relay are hot or cold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, call to preloadedQuery.source?.toPromise()
here results in a already resolved promise. If you have better name suggestion for serverSidePostQuery
let me know 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a blurb about this to the documentation in /website
? Other than that everything looks good to me!
Added it to docs! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!
This is now published in |
Adds
serverSidePostQuery
function option to relay-nextjs which allows to access returned query data andNextContext
after the query has finished during SSR. This allows to handle stuff like 404 status codes for non-existing pages. Related: #15Example usage:
Any feedback welcome.