vercel / next.js

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

Rewrites break down _next/data request? #38790

Open yunsii opened 2 years ago

yunsii commented 2 years ago

Verify canary release

Provide environment information

WSL:

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Apr 2 22:23:49 UTC 2021
Binaries:
  Node: 16.15.0
  npm: 8.5.5
  Yarn: 1.22.18
  pnpm: 7.5.0
Relevant packages:
  next: 12.2.3-canary.14
  eslint-config-next: 12.2.2
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

When I config rewrites, _next/data request like http://dev.next-ssr1.com:3000/_next/data/development/ssr1/parent/apple.json?child=apple will rewrite to [...fallback].page.tsx. Otherwise http://dev.next-ssr1.com:3000/_next/data/development/ssr1/test.json is ok.

Expected Behavior

_next/data request should act like _next/static?

Link to reproduction

https://github.com/yunsii/next-ssr-multiple-apps

To Reproduce

In contrast, from / to /test will find test.json is ok.

Domino9697 commented 2 years ago

I am also encountering the issue !

Instead of being pure JSON, the next data file contains the HTML of the rewrited page. Tested on Next v12.2.2 and 12.2.3.

fasani-tx commented 2 years ago

@Domino9697 any update on that?

yunsii commented 2 years ago

workaround:

rewrites: {
  // ...
  afterFiles: [
    {
      source: `ssr1/:path*`,
      has: [
        {
          type: 'host',
          value: `dev.next-ssr1.com`,
        },
      ],
      destination: `/:path*`,
    },
  ]
}

Add another rewrite rule to remove unnecessary path segment.

yunsii commented 2 years ago

After upgrade to next@12.3.1, It seems fixed.

And 12.2.5 is also work as expected.

mderrick commented 1 year ago

I'm still facing this issue on 13.1.1 whereby I'm using a fallback like:

fallback: [
      {
        source: '/:path*',
        destination: `https://x.com/:path*`,
      },
    ]

and _next/data/development/en/y.json returns the HTML from pages/y/index.tsx.