Replies: 33 comments 1 reply
-
IMO this will be very useful but I would add this behavior in the My proposal: export async function getServerSideProps(){
return {
props: await fetchProps(),
navigation: false,
}
} I dunno how feasible is to implement this. But doing in this way it would be very useful. |
Beta Was this translation helpful? Give feedback.
-
@aralroca the way that you're suggesting it would require getServerSideProps to be executed before knowing it shouldn't execute. Which makes it not feasible for what the feature request wants to achieve. |
Beta Was this translation helpful? Give feedback.
-
Removed the first contentful paint mention as it's incorrect, this feature wouldn't make FCP faster for initial load which is the only thing that eg Google tracks. |
Beta Was this translation helpful? Give feedback.
-
@timneutkens I think it's very accurate
https://developers.google.com/web/tools/lighthouse/audits/first-contentful-paint |
Beta Was this translation helpful? Give feedback.
-
Overall putting it on the |
Beta Was this translation helpful? Give feedback.
-
It's tricky to define it as such as FCP measures the time from navigation of a full browser navigation. In case of client-side navigation you already have rendered DOM and only bits are replaced in the UI (eg header/footer could persist). |
Beta Was this translation helpful? Give feedback.
-
Yes. That's true... However, it will be useful to do it on the page. Probably outside of export const config = {
getServerSideProps: { navigation: false }
}
export async function getServerSideProps(){
return {
props: await fetchProps()
}
} |
Beta Was this translation helpful? Give feedback.
-
I agree, adding it to I think for the short path we could go with an additional parameter. |
Beta Was this translation helpful? Give feedback.
-
But I imagine that when you have some skeletons / spinners + |
Beta Was this translation helpful? Give feedback.
-
I 100% agree, but as I said before the responsibility lie already in |
Beta Was this translation helpful? Give feedback.
-
It is not feasible to add short term solutions for something as popular as Next. If they add a feature, they'd probably have to support it for years. Agree with @aralroca, I don't think fixing this at the That said, I'd still like to see a way to control fetching of data on a client side page navigation. Especially, with useSWR, where I'd like some |
Beta Was this translation helpful? Give feedback.
-
I agree but It's better to try out things, collect feedback rather than waiting weeks or months for an RFC. For that, we can use "experimental" flags. @timneutkens How much effort is needed to implement it in the AMP like way? |
Beta Was this translation helpful? Give feedback.
-
+1 for config to skip |
Beta Was this translation helpful? Give feedback.
-
I just tried Next for the first time last week and was amazed to discover this wasn't the way it worked. The behaviour (default or via an option) should be: On the first visit to the Next app it server side renders The speed and SEO benefit of SSR only applies on initial load of the app when you have extra round trips (url -> server -> client -> API -> client). Once the initial application is loaded, then when you click a new page a client-side app becomes (Client -> API -> Client) which is exactly the same trips as (Client -> Server -> Client). But much faster client side because the server doesn't have to do the heavy lifting of rendering the page AND if you already have the data you can display the page instantly. I really hope I am just missing setting in Next, because this is a pretty fundamental idea of SSR and App hydration, and something I've been doing for 4+ years with React apps. Basic App: People List page, loads all the people and some data about the, If I visit the people page, it should server side render the page, and include the all the people. If I visit the person page, it should server side render the page, with all the data about the one person. Now its fast for |
Beta Was this translation helpful? Give feedback.
-
I think to solve this issue, we need one more |
Beta Was this translation helpful? Give feedback.
-
@JClackett Did you add cache-control headers to the request? It sounds like you're using the Apollo cache which is on the client-side.
@goleary You can fetch data client-side using React via vanilla
How frequently does the data change? You can also use |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response @leerob!
On the order of a few times per day. I think this approach would work for my use case although I can see it resulting in a unappealing flashing of content as soon as the client side hook runs if there is a difference between the SSG version and what's presently in firestore. I would also imagine that with this set up the server is rebuilding pages when not necessary as a user is paging around the app since they already have the most up to date version of the data client-side. |
Beta Was this translation helpful? Give feedback.
-
The server will only rebuild the page if the time specified in |
Beta Was this translation helpful? Give feedback.
-
Thanks for the link, I'll have to play around with static regeneration as it does sound promising for this use case.
Oh and to this, yes I realize. I should have said: "the lack of ability to fetch data clientside on clientside navigation without blocking on server data fetching is definitely going to hold me back from using it with my current tech stack." I still wish I could enable a setup that uses |
Beta Was this translation helpful? Give feedback.
-
So.... there are two ways it looks like to solve this problem. The first is that the page is aware whether other pages should have the props it needs (either via config on the page or via another method). The second is to pass the props from one page to another (if it has them). I think the latter makes a whole lot more sense. Take these scenarios:
In the first scenario, you may not have all the props the page needs, and it would be better/faster to let Next.js go and retrieve them. In the second scenario, you may have everything that is needed and can pass those props to the page. Therefore, to me, it seems better to add a propertly to the Some have mentioned that this might lead to mistakes in constructing the As an example: function ProductLink({ id, title }) {
// fetchProductFromIndexedDb() returns a promise that resolves to an
// an object, or undefined if it doesn't exist.
const fetchProduct= useCallback(() => fetchProductFromIndexedDb(id)), [
id,
]);
return (
<Link href="/product/:id" as={`product/${id}`} propFetcher={fetchProduct}>
<a>{title}</a>
</Link>
);
} If the props can't be retrieved (i.e. they don't exist locally), Next.js can fallback to it's default behavoir and load the page. |
Beta Was this translation helpful? Give feedback.
-
In the example I just gave it could be a method on the page itself (since the only dependency is the id which is passed in the URL), but let's instead consider something like this: function ProductLink({ id, title, description, imgUrl }) {
const fetchProduct= useCallback(() => ({
id,
title,
description,
imgUrl
}), [
id,
title,
description,
imgUrl
]);
return (
<Link href="/product/:id" as={`product/${id}`} propFetcher={fetchProduct}>
<a>{title}</a>
</Link>
);
} In a scenario like this, the page doesn't have the context (a listing page) of the page you were on previously, so there is no way for it to retrieve client side props (other than making an API request, which Next.js will do for you anyways). |
Beta Was this translation helpful? Give feedback.
-
I think this issue could be solved by server components? Using a shared component for the page would allow the data fetching to happen on the server OR the client (or using a server component would force a server render, using a client component would skip server rendering). |
Beta Was this translation helpful? Give feedback.
-
Any activity on this? You really need to think about it. I don't understand why this issue takes so little attention from community... |
Beta Was this translation helpful? Give feedback.
-
Coming into next, If I do a client-side navigation to a route containing As mentioned, we can do a workaround with |
Beta Was this translation helpful? Give feedback.
-
Any activity on this? |
Beta Was this translation helpful? Give feedback.
-
For anyone looking for a solution, I've hacked my way around this using a query param that I can check for in It's really far from ideal because of how much sequencing is required, but with |
Beta Was this translation helpful? Give feedback.
-
I've written a short RFC discussing a possible way to introduce server-side only initial props, and would appreciate feedback: |
Beta Was this translation helpful? Give feedback.
-
Here's a hack to solve this problem. I am using this solution. |
Beta Was this translation helpful? Give feedback.
-
I found a hacky solution that monkey-patches |
Beta Was this translation helpful? Give feedback.
-
Feature request
Is your feature request related to a problem? Please describe.
@aralroca shared some useful insights on how he archived his app performance.
He still relies on
getInitialProps
insteadgetServerSideProps
because it allows him to skip client-side data fetching on route change. He loads the data on the nextuseEffect(..., [])
lifecycle. SSR is not affected. In that scenario, he can ship the app skeleton faster to the user and load the data afterward on the client.This sounds reasonable when your static content dominate the page which is often the case.
Describe the solution you'd like
Working PR which demonstrates the behavior by defining
skipDataFetch
onLink
component. https://github.com/StarpTech/next.js/tree/add/skip_data_fetchAdditional context
Beta Was this translation helpful? Give feedback.
All reactions