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: Marker hook for server-side data #85

Closed
wants to merge 2 commits into from
Closed

Conversation

leops
Copy link

@leops leops commented Nov 11, 2018

View rendered

This RFC proposes a useSerializable hook to automate the extraction, and subsequent hydration of serializable server-side data.

@sebmarkbage
Copy link
Collaborator

sebmarkbage commented Nov 12, 2018

Some way to transfer serializable data from server to the client is certainly in scope for the new server rendering infrastructure that supports Suspense. Unclear what the mechanism to do so is though. We probably need to be further along with the rest of the pieces before that becomes clear.

@leops
Copy link
Author

leops commented Nov 13, 2018

This is why I tried to design this RFC in isolation, and leave as much as possible "unspecified", since I make no assumption on the specifics of how Suspense on the server will work. Essentially this is just the result of me experimenting with how an SSR framework might work with React.lazy by (poorly) polyfilling Suspense for the server, and trying to figure out a way to declaratively mark data for extraction / hydration. In the end I tried to make something that should "just work" unless the final API goes in a drastically different direction.

@gaearon
Copy link
Member

gaearon commented Aug 18, 2021

the resulting resource object is stored in the hook state chain and returned (this part is essentially doing useMemo(createResource, [])).

This is pretty different from the direction we're going with the Suspense library design, which uses a centralized cache Map to hold data (rather than per-component memory). You can read more about this API here: reactwg/react-18#25.

There is still a question of whether we'd want the cache to be "transferable" via a built-in React API, or if you have to use Server Components (#188) and rely on transferring only the rendered output. We don't know how that will work yet. But it seems safe to say that the API shape will likely be different so I think we can close this more confidently. Appreciate the exploration though — it's just that we don't have much to say except that it'll likely be different.

@gaearon gaearon closed this Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants