Skip to content

Defer getServerSideProps on client-side navigation #32243

Answered by leerob
rafaelalmeidatk asked this question in Help
Discussion options

You must be logged in to vote

The original problem proposed is now solved with the Next.js App Router (Next.js 13+).

The root issue was wanting to fetch data on the server, but not block navigation. With improvements in React 18 and the new Next.js App Router, this is now possible using Instant Loading UI (loading.js), React Suspense, and HTTP streaming.

Clicking a link to a page that requires data to be retrieved on the server can immediately provide feedback to the user, showing an instant loading state, while the request (made inside an Async Component) can await the results needed.

// app/loading.ts

export default function Loading() {
  // You can add any UI inside Loading, including a Skeleton.
  return <Loading…

Replies: 56 comments 56 replies

Comment options

You must be logged in to vote
2 replies
@mapsgeek
Comment options

@ianldgs
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@uladkasach
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@FINDarkside
Comment options

@Axxxx0n
Comment options

Comment options

You must be logged in to vote
11 replies
@eseQ
Comment options

@Dema
Comment options

@ianldgs
Comment options

@o-az
Comment options

@Dema
Comment options

Comment options

You must be logged in to vote
1 reply
@eseQ
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
17 replies
@leerob
Comment options

@hysan
Comment options

@erikash
Comment options

@mycolaos
Comment options

@erikash
Comment options

Answer selected by leerob
Comment options

You must be logged in to vote
4 replies
@tienlx97
Comment options

@tienlx97
Comment options

@Gelio
Comment options

@longyarnz
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ZimM-LostPolygon
Comment options

@ristomatti
Comment options

Comment options

You must be logged in to vote
4 replies
@ianldgs
Comment options

@akhmadshin
Comment options

@ianldgs
Comment options

@akhmadshin
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
Converted from issue

This discussion was converted from issue #13910 on December 07, 2021 16:13.