vercel / next.js

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

When app is passed through a proxy, RSC payload fails to load. #67444

Open jmarioste opened 2 months ago

jmarioste commented 2 months ago

Link to the code that reproduces this issue

https://github.com/jmarioste/test-proxy-app

To Reproduce

In our company, many of our customers are institutions and/or universities that uses proxy to access our app. We recently refactored our app to next 14 app router but seems to not hydrate and doesn't work when passed through their proxy (e.g., ezproxy). Error: Connection closed. is thrown. I can't post the exact details because of confidentiality. I'll just use google translate as an example. This doesn't happen when using the /pages directory

  1. Go to a proxy website, in this case, i'm using translate.google.com
  2. Enter website: https://test-proxy-app.vercel.app/contact
  3. Go to https://test--proxy--app-vercel-app.translate.goog/contact?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp&_x_tr_hist=true
  4. Check network tab. Notice that the RSC payload returns 400 HTTP error. image

Current vs. Expected behavior

Current behavior:

  1. When passed through a proxy service (ezproxy, etc) where a different domain is produced, app router fails to hydrate or the rsc payload fails to load in the network tab.
  2. Sometimes, Error: Connection closed. is thrown.

Expected behavior:

  1. rsc payload should not fail
  2. page should hydrate properly and there should not be any Error: Connection closed.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home Single Language
  Available memory (MB): 15792
  Available CPU cores: 16
Binaries:
  Node: 20.8.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.0-canary.54 // Latest available version is detected (15.0.0-canary.54).
  eslint-config-next: 15.0.0-canary.54
  react: 19.0.0-rc.0
  react-dom: 19.0.0-rc.0
  typescript: 5.5.3
Next.js Config:
  output: N/A

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

Not sure

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

Vercel (Deployed), Other (Deployed)

Additional context

This doesn't happen on pages directory, only app directory using react server components.

kaisic1224 commented 2 months ago

I believe that as you said, the error message only occurs on a proxy where the original url changes. I tested this on PlainProxies and there is no error through that proxy. However, the RSC fetch parameter is a hash that includes a header parameter called Next-Router-State-Tree which happens to be different from the original website and the proxied website.