-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Milestone
Description
Feature request
Is your feature request related to a problem? Please describe.
When clicking in a link to a page that uses getServerSideProps, the navigation will be kept in hold until the server response is complete, then the navigation will start. I want to be able to defer the getServerSideProps data-fetching until the client-side navigation has been completed. Similar to the behavior of getStaticProps with fallback: true.
Describe the solution you'd like
- When directly accessing the page (e.g., typing the URL and pressing Enter), it should be server-side rendered
- When navigating to the page from another page, the navigation should happen immediately. The page will be rendered with a loading state. When the navigation is completed, the
gSSPrequest should be fired to fetch the content and send it through the page props.
I should be able to opt-in this behavior with a flag in the return of gSSP. The router should have a flag to tell if the page is fetching data:
// pages/example.js
function Post({ post }) {
const router = useRouter()
// If the page data is not yet fetched, this will be displayed
// initially until getServerSideProps() finishes running
if (router.isFetchingAfterDefer) {
return <div>Loading...</div>
}
// Render post...
}
export async function getServerSideProps(context) {
return {
props: { ... },
deferOnClientSideNavigation: true,
}
}Describe alternatives you've considered
Using getInitialProps/getServerSideProps to detect if it is client-side navigation and send empty props, then repeat the fetch logic in the component code
jpedroschmitz, tomdohnal, blazeu, arso1er, sromexs and 147 morefaisalpathan, JonCognioDigital, smitronin, Denislwn, casinX and 43 moreBrennerSpear, UthpalaHeenatigala, Aaike, tiberiur, ramrami and 26 more
Metadata
Metadata
Assignees
Labels
No labels