vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.8k stars 26.95k forks source link

pageProps(JSON) by getStaticProps is returned as an empty object in the pageProps of the index page of basePath. #63561

Open edoko opened 7 months ago

edoko commented 7 months ago

Link to the code that reproduces this issue

https://github.com/edoko/next-ssg-test/tree/main

To Reproduce

  1. Configure a monorepo and basePath
  2. Add middleware Just return NextResponse.next()
  3. Add getStaticProps in /apps/sub/pages/index.tsx and show the message of props in dom.
  4. Add a next/link with href='/sub' in /apps/main/pages/index.tsx
  5. Add a next/link with href='/sub/my' in /apps/sub/pages/index.tsx and create the page(/apps/sub/pages/my.tsx)
  6. Deploy to Vercel and open the main page https://deploy-main-app (/apps/main)
  7. Click the link with /sub and move the /sub page
  8. Show the message(Hello from getStaticProps!) of getStaticProps
  9. Click the link with /sub/my and move the /sub/my page
  10. Press the back button, move the /sub page and not showing message of getStaticProps
  11. In the Network tab, index.json also appears empty object.

Current vs. Expected behavior

Current: https://next-ssg-test-main-app.vercel.app/sub/_next/data/{build_id}/index.json is {}.

Expected: https://next-ssg-test-main-app.vercel.app/sub/_next/data/{build_id}/index.json is

{
  props: {
    pageProps: {
      message: "Hello from getStaticProps!"
    },
    __N_SSG: true
  }
}

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:31 PST 2024; root:xnu-10063.101.15~2/RELEASE_X86_64
  Available memory (MB): 32768
  Available CPU cores: 6
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 4.1.1
  pnpm: N/A
Relevant Packages:
  next: 14.2.0-canary.34 // Latest available version is detected (14.2.0-canary.34).
  eslint-config-next: 14.2.0-canary.34
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

I'm also running a real project using yarn workspace and basePath. middleware is also being used. If I used getStaticProps in '/index' of basePath, if I go back after moving to another page or click the link that moves to /, pageProp is returned empty.

The first reproduced version was v13.5.2, and the same issue occurred even when updated to v14.1.0 and v14.1.4, and the same problem occurred even when using v14.2.0-canary.34.

So I created a project that could reproduce the above problem.

experience the problem for here: https://next-ssg-test-main-app.vercel.app/

VillageR88 commented 7 months ago

Can you post direct link to your index.json?

edoko commented 7 months ago

Can you post direct link to your index.json?

@VillageR88 I've put the repo address above.

root: https://github.com/edoko/next-ssg-test/blob/main/package.json apps/main: https://github.com/edoko/next-ssg-test/blob/main/apps/main/package.json apps/sub: https://github.com/edoko/next-ssg-test/blob/main/apps/sub/package.json

edoko commented 6 months ago

I am still experiencing this issue. And recently a new issue was created by a user who is experiencing a similar problem. #64910

I was wondering if vercel is aware of this issue.

I think I'll probably end up abandoning the use of basePath in Next.js in favor of using subdomains. The use of basePath seems to have a number of issues 😢