A dynamic SSR rendered page of mine is completely blank when users go back to it from another page.
<Link/> to the home page (which is a static, standard next.js page).When I "Go back" in my browser, the page should display exactly as it did before.
Issue doesn't occur for static pages, only dynamic SSR pages.
I have the same issue with dynamic pages. The back button works well when a user goes back to a static page (no [id].js, no ?param=param, etc). But it doesn't work when a user goes back from one dynamic page to another.
After clicking the back button I see the wrong state in window.history. as is okay, but url is like I didn't click back button.

I face this issue on 3 projects and this is awful.
Please provide a full demo so we can look into this.
@Timer
Reproducible here:
Steps to replicate

Note: Replicable only when query paraments are present
The same thing happens to me in production and development, the second time I return to the home page.
Although error occurs on the home page, the error seems to come from the dynamic routes. I put my [slug].js component, which is where the error comes from.
I followed Strapi's example from the example repository.
import {getAllPostsWithSlug, getPost, getRecommendedPosts} from '@src/helpers/api'
import Head from 'next/head'
import markdownToHtml from '@src/helpers/markdownToHtml'
import HeaderTop from "@src/components/Layout/Header/HeaderTop";
import HeaderWithBackground from "@src/components/Layout/Header/HeaderWithBackground";
import Footer from "@src/components/Layout/Footer";
import PostContent from "@src/components/Post/Content";
import config from "@src/config";
export default function Post({post, recommendedPosts}) {
return (
<>
<Head>
<title>{post.title}</title>
</Head>
<HeaderTop/>
<HeaderWithBackground/>
<div className="main">
<PostContent post={post} recommendedPosts={recommendedPosts}/>
</div>
<Footer/>
</>
)
}
export async function getStaticProps({params, preview = null}) {
const post = await getPost(params.slug, preview);
const recommendedPosts = await getRecommendedPosts(3);
const content = await markdownToHtml(post?.[0].content || '');
return {
props: {
preview,
post: {
...post?.[0],
content,
},
recommendedPosts
},
}
}
export async function getStaticPaths() {
const allPosts = await getAllPostsWithSlug()
return {
paths: allPosts?.map((post) => `/blog/${post.slug}`) || [],
fallback: false,
}
}
I see many other similar issues that have been ignored 🤷♂️
The whole problem seems to come from the next/link component, If I use the "a" tag directly, everything works fine. Can't I use the Linkcomponent in static pages? In the documentation I don't see anything mentioned about.
Similar Problem Here:
https://pokedex-tutorial.vercel.app/
You can check the code here:
https://github.com/BinPar/pokedex-tutorial
You can reproduce it:
@Timer @timneutkens Any update on this? I have resorted to using instead of for dynamic routes for the time being. Or perhaps any other workaround?
Hi, these sound related to https://github.com/vercel/next.js/issues/16028 which was fixed in https://github.com/vercel/next.js/pull/16477 and is available on the latest canary of Next.js v9.5.3-canary.21. Can you upgrade and see if the behavior is corrected for you?
@ijjk Issue got fixed for me
https://github.com/collegewap/next-route-issue
@ijjk Fixed over here :) Thanks!
Thanks for testing that @collegewap @Skarian! I'm going to close this since the related reports seem to be fixed. If anyone else is still encountering this please respond with additional details and we can investigate further.
Similar Problem Here:
https://pokedex-tutorial.vercel.app/
You can check the code here:
https://github.com/BinPar/pokedex-tutorial
You can reproduce it:
- SSR the home page (https://pokedex-tutorial.vercel.app/)
- Scroll down
- Select a pokemon
- Click the back (at the bottom)
- The home page goes to the top
- Scroll down
- Select a pokemon
- Click the back (at the bottom)
- Now it works... every time except after the initial SSR
In my case it is not fixded using: "next": "^9.5.3-canary.21"
@drnachio this issue seems to be un-related to the reproduction steps you are describing as the content is loaded correctly when following the steps, it seems that yours is more related to scroll restoration
I had a similar issue: every page reload was displaying blank page. I had to hard reload and remove cache every time.
It is solved with ^9.5.3-canary.21 👍