-
Notifications
You must be signed in to change notification settings - Fork 441
[WIP] Possible evolution of the Relay integration with Next.js v13 #270
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
base: main
Are you sure you want to change the base?
Conversation
| } | ||
| const data = record.response.data ?? null; | ||
| if (data != null) { | ||
| environment.commitPayload(record.operationDescriptor, data); |
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.
Just a thought about alternative, this could happen more granularly at useFragment if we change Relay implementation. If the fragment can't be resolved from the store, we could check if the fragment owner exist in a global fetchedQueries and commit if not.
|
I wonder if this could work with If we can have a fragment await until it get's the data that it needs, and then have them nested, and some of them using @defer, that would make the Server components experience for this very very nice. You could have skeletons at different levels of data fetched while still only using client components at the leafs. I have been trying to look into how Relay works internally to understand if it's possible. I think, if the hooks right now are able to suspend until deferred data is loaded, it should "in theory" be a matter of instead being able to await the data for a fragment instead. |
| } from "relay-runtime"; | ||
| import { networkFetch } from "./environment"; | ||
|
|
||
| const fetchedQueries: FetchedQuery[] = []; |
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.
Wouldn't this leak data between requests and cause a memory leak?
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.
maybe we can use AsyncLocalStorage/async_hooks for this.
|
@alunyov any updates to share? |
Sorry, no real updates here. I'm on parental leave, maybe I will get back to this in a few month. |
|
This might run into garbage collection issues without usePreloadedQuery/useQuery or environment.retain()... I ran into this with a similar setup when I was running multiple queries on input events after the page fetch. |
Note: This is WIP and not ready to be merged. I’m sharing for feedback and adjustments on the direction.
Summary:
Data-fetching for routes is happening in the Relay Server Components, using
fetchQuerythis version is different from what we export fromrelay-runtime- (maybe we’ll need a different name). Internally, it fetches the query, publish to the relay store. ThisfetchQuerycan only be called on the server.RelayRoot- RSC, simple wrapper, that passes serialized list of fetched queries to theRelayClientRootRelayClientRoot- client component that wraps the children with Relay context provided, and publishes the fetched server queries to the client store, so the state of the local store is matching the one on the server.RelayClientRootis normal client-first relay with hooks and things... But there is no root query component (withusePreloadedQueryor similar...).useFragment(thanks @sibelius for the question: [WIP] Possible evolution of the Relay integration with Next.js #269 (comment)) - this will allow for individual server components define own data requirements, and the view will be fully server-rendered, with possible client leafs. The fragments composed into a query and fetched in the top RSC withfetchQuery.Note on the API naming: we may want to name these
useFragmentandfetchQuerydifferently, to avoid possible confusion with similar APIs forreact-relayandrelay-runtime.So, this is a “sketch” of the possible integration, so many things may not work:
seenQueriesbut may not work in general case.RelayClientRoot.Not sure if it’s working:
useLazyLoadQuery- underRelayClientRoot.(should work, I think)