-
-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Defer next page + loading bar
A neat page transition is to preserve the current page and defer showing the next page until it's fully loaded, while showing a loading bar (like YouTube or nprogress). I think it's already possible for the user to implement this?
How about we make this the default behavior?
Default
Currently, vike-react
doesn't provide any default page transition strategy, but I think it should. (While enabling the user to override this default.)
<Suspense>
How about pages that have suspense? (More precisely: when the next page has one or multiple <Suspense>
boundaries.) In particular when using vike-react-query
and vike-react-apollo
.
With @nitedani we already have ideas about this (withFallback()
and a new setting +Loading.js
).
Main <Suspense>
How about this: let the user declare the "main" <Suspense>
boundary. As long as this main suspense isn't resolved then keep showing the old page with a loading bar. As soon as this main suspense is resolved, then show the next page (consequently showing all suspense boundaries that are still loading).
For example, a product page would start to be shown to the user upon page navigation only after the product content of the page is fetched from the database.
In other words, it's blocking the rendering the next page. API example:
import { useSuspenseQuery } from '@tanstack/react-query'
import { await } from 'vike-react-query'
const Movie = await(
({ id }: { id: string }) => {
const result = useSuspenseQuery({
queryKey: ['movie', id],
queryFn: () =>
fetch(`https://brillout.github.io/star-wars/api/films/${id}.json`)
.then((res) => res.json())
})
const { title } = result.data
return (
<div>
Title: <b>{title}</b>
</div>
)
}
)
There could be several await()
components for a single page. (Although, in the (vast?) majority of cases, the user would likely define only one await()
component.)
I ain't sure how an implemention would look like, but IIRC React 18/17 introduced a new feature that was addressing this use case. (Start rendering the next page in a seperate virtual DOM while preserving the current page.)
No <Suspense>
What should happen when there isn't any <Suspense>
boundary? (Which is also possible with vike-react-{query,apollo}
when the user doesn't use useFallback()
.) I guess this is the default behavior, i.e. defer showing the next page + loading bar.
See also