On-demand server component rendering
Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
African Slender-snouted CrocodileOP
More of a theoretical question, but does anyone think we will ever see on-demand server component rendering? An on-demand server component would be implemented like any other fetch that returns RSC, but could be triggered by client-side triggers, such as a state change. Of course, it's more complex than that - state would need to be serializable,
For example, right now I have a list that I want to render from some data fetched from an API, given a list of IDs stored in client state. Of course, I can simply make a route handler that wraps my external API and takes the IDs as a body (and return JSON the client renders), but it would be super cool if I could make the list component a server component (imported into the client component with the state) that consumes the client state as a prop and actually fetches and renders the list on the server, returning RSC the client can then show.
children would not be supported, ref objects wouldn't work and, probably worst of all, it breaks the boundary between client/server components as it would allow server components to be imported into client components. But even with all those limitations, it still feels like it would be a very powerful tool and, to me, more useful than most of the existing features (like parallel routes as, unless you either don't care about props or can get away with using URL params, you can't pass data to them).For example, right now I have a list that I want to render from some data fetched from an API, given a list of IDs stored in client state. Of course, I can simply make a route handler that wraps my external API and takes the IDs as a body (and return JSON the client renders), but it would be super cool if I could make the list component a server component (imported into the client component with the state) that consumes the client state as a prop and actually fetches and renders the list on the server, returning RSC the client can then show.