Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static exported with getStaticProps and external fetch fails with url's followed by trailing slash and query parameter #9929

Closed
lucaziz opened this issue Jan 3, 2020 · 1 comment · Fixed by #10140
Milestone

Comments

@lucaziz
Copy link

lucaziz commented Jan 3, 2020

Bug report

Describe the bug

Using getStaticProps and linking to a local JSON file (exporting static), I notice that if your path has trailing slash plus a query parameter (ex: my.path.com/subpath/?query=1), pathname gets broken and fail to request data.

To Reproduce

  1. Go to a Next page and build using getStaticProps with external fetch (like Static generation https://github.com/zeit/next.js/blob/canary/docs/concepts/_data-fetching.md)
  2. Export project using next export
  3. Navigate to a page with a trailing slash at the end and add a query parameter after that (ex: my.path.com/subpath/?query=1)
  4. See error

Expected behavior

NextJs should handle this path behavior even it's not that common.

System information

  • OS: macOS
  • Browser chrome
  • Version of Next.js: [e.g. 9.1.7-canary.16]

Additional context

Just a small edge case fix.

I know this still a concept, but it looks like is an easy fix. I solved changing (temporary) my local nextjs code at file lib/router/router.js and changed line 63 (inside the function _getStaticData from this:

pathname = !pathname || pathname === '/' ? '/index' : pathname;

to:

pathname = !pathname || pathname === '/' ? '/index' : (pathname.endsWith('/') ? pathname.slice(0,-1) : pathname);
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants