question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `getStaticPaths` in combination with `trailingSlash: true` leads to invalid json prefetching

See original GitHub issue

Bug report

Using getStaticPaths in combination with trailingSlash: true leads to invalid json prefetching. For a link to a dynamic route, the json file that is prefetched includes an invalid slash in the path, causing a 404 to be returned. However, when clicking the link and landing on the dynamic page the correct json file is fetched.

To Reproduce

  1. Configure
// next.config.js
module.exports = {
  trailingSlash: true,
};
  1. Add dynamic route
// pages/[name].js
export default function Hello({ name }) {
  return <div>Hello {name}</div>
}

export function getStaticProps(context) {
  return {
    props: {
      name: context.params.name
    }
  };
}

export function getStaticPaths() {
  return {
    paths: [
      { params: { name: 'world' } }
    ],
    fallback: false
  };
}
  1. Add link to dynamic route
// pages/index.js
import Link from 'next/link'
export default function Home() {
  return (
    <div>
      <Link as="/world" href="/[name]">
        <a>Hello world</a>
      </Link>
    </div>
  )
}
  1. Export using next build && next export
  2. Open root page
  3. Observe a network request for https://example.com/_next/data/some-hash/world/.json returning a 404

Expected behavior

The correct https://example.com/_next/data/some-hash/world.json is (pre)fetched

System information

  • OS: macOs
  • Browser (if applies): chrome
  • Version of Next.js: 9.5.5
  • Version of Node.js: v12.18.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
bernardodestefanocommented, Oct 19, 2020

I have exactly the same issue, any updates?

2reactions
emadiciocommented, Oct 19, 2020

Following on this. It is a really serious issue for our project, as not being able to fetch the pages .json breaks prefetching of links, causing the entire app to re-render when you click on a link and subsequent loss of data in React contexts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetch error when building Next.js static website in production
I use getStaticProps and getStaticPath fetch from an API route. First when I npm run build FetchError: invalid json response body at ...
Read more >
Trailing Slash - next.config.js
Configure Next.js pages to resolve with or without a trailing slash. ... getStaticPaths · getStaticProps · Incremental Static Regeneration.
Read more >
Next.js Tutorial - 27 - getStaticPaths fallback true - YouTube
Courses - https://learn.codevolution.dev/⚡️ Checkout Taskade! https://www.taskade.com/ Support UPI - https://support.codevolution.dev/  ...
Read more >
Next.js Tutorial - 25 - Fetching Paths for getStaticPaths
Courses - https://learn.codevolution.dev/⚡️ Checkout Taskade! https://www.taskade.com/ Support UPI - https://support.codevolution.dev/  ...
Read more >
@next/mdx: Versions | Openbase
Disable Image Optimization API when next.config.js has unoptimized: true : # ... Add clarity in docs for using exportPathMap with getStaticPaths : #39813 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found