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
Support sub-routes #1002
Comments
@wizardlyhel came up with a brilliant idea for sub-routes, partial refetching in RSC, and an option for continuing to use the new Remixed React Router (WIP). Here's my attempt at writing it down! tl;dr - lean into Remix's pattern of "layout routes" to create multiple server component entrypoints for a Hydrogen app Here's how this could work in Hydrogen: Components
Pretty much the same as today, except If devs have different "areas" of a site, they could even provide other layouts:
Where To make this work, we convert export default function App() {
// Layout stuff here. Fetch data if you want!
return (
<Layout>
<Outlet />
</Layout>
);
} Next, as part of our dev/build process, we generate a You can inspect this by visiting https://remix.run/docs/en/v1 and typing The clientToday, our entry-client looks a lot like this: function ClientApp() {
// makes a fetch request to the RSC endpoint
const response = useServerResponse(serverState);
return (
<Suspense>
{response.readRoot()}
</Suspense>
);
} With this new proposal, the client would be much more aware of the app structure than it is today. We provide our function ClientApp() {
// This is generated programmatically. This is only a visual representation
// of what is inferred based on parsing the manifest.
return (
<>
<Suspense>
<Content route="App.server">
<Suspense>
<Content route="product.server">
</Suspense>
</Content>
</Suspense>
</>
);
}
function Content({route}) {
// makes a fetch request to the RSC endpoint
const response = useServerResponse({...serverState, route});
return (
<Suspense>
{response.readRoot()}
</Suspense>
);
} Note: this is a bit contrived, because we couldn't simply pass Speaking of which: this is where (Remixed) React Router comes in! RR is perfectly set up to be used on the client:
This effectively accomplishes what this issue aims for: a true sub-route experience, where the outer layouts stay rendered while the contents inside transitions as the RSC request changes. The RSC serverSince we're passing The SSR serverSSR emulates what Potential issues:
|
Regarding the issues:
|
What would be the things that determine what is a layout component and what isn't? Something in the name? Something the file exports? |
Would it work without the underscores?
Where |
I bet we might be able to make that work @frandiox, but I think there's still some value in being explicit, especially when there get to be many routes. Is this also an area where being opinionated where convention over configuration is okay? |
I am less worry about sharing data between layout components. I think we can make that an invisible stitching with
|
Chiming in to say this sounds AWESOME. We've done some looking into Remix as a option and loved some of what they were doing. Being able to incrementally adopt they're routing where it makes sense would be a huge win. 🚀 |
Wouldn't infinite scrolling of product lists be a great application of this? Would love to make that pagination super easy style super easy and performant. So many UX considerations to make it good -- URL param updating, scroll position restoration, memory management with virtualized lists, intersection observer, skeleton components, etc. |
@wizardlyhel is now working in this in #1858 |
When transitioning between pages in Hydrogen, an RSC request is sent to the server. Depending on what data requests are necessary, the transition can be noticeably slow while waiting for the RSC response. If Hydrogen supported sub-routes, on each RSC request, we should be able to determine what requests are necessary to re-run.
Consider a simplified PDP page:
When this page is directly loaded (or hard refreshed), data needs to be fetched for the header as well as the product information. If the user clicks the link for "Freestyle Collection", currently the RSC request will re-fetch everything for a new page render. We can 1) cache those request results and 2) try to optimize the RSC response to the browser. But it would be ideal if the RSC endpoint can be smart and know that the header did not change at all. This would be possible if the product details are in a sub-route, and as long as the destination route is a sibling sub-route.
Questions
a. We would need to make sure the RSC response supports both nested and base route changes
The text was updated successfully, but these errors were encountered: