vite icon indicating copy to clipboard operation
vite copied to clipboard

vite ssr - spaces in url leads to different req.pathname

Open mkilpatrick opened this issue 3 years ago • 1 comments

Describe the bug

Making a request in SSR mode to http://localhost:5173/indextest/dangiel1 leads to the req.originalUrl looking like /indextest/dangiel1 but making a request to http://localhost:5173/index%20test/dangiel1 (note the %20 space) leads to: /@id/__x00__/index%20test/dangiel1

Reproduction

N/A

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 954.67 MB / 64.00 GB
    Shell: 5.1.16 - /usr/local/bin/bash
  Binaries:
    Node: 17.9.0 - ~/.nvm/versions/node/v17.9.0/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v17.9.0/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v17.9.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.134
    Safari: 15.5

Used Package Manager

npm

Logs

No response

Validations

mkilpatrick avatar Jul 29 '22 23:07 mkilpatrick

It's worth noting that my route handling is set up to handle a special root page:

  app.use(
    /^\/(.+)/,
    serverRenderRoute({ vite })
  );

  // Serve the index page at the root of the dev server.
  app.use(
    "/",
    indexPage()
  );

mkilpatrick avatar Jul 30 '22 17:07 mkilpatrick

Hello @mkilpatrick. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

github-actions[bot] avatar Aug 01 '22 13:08 github-actions[bot]

It doesn't reproduce with a simple setup. Please provide a reproduction. https://stackblitz.com/edit/github-rfwq5p?file=src%2Fentry-server.js,server.js

sapphi-red avatar Aug 01 '22 13:08 sapphi-red

Here's a reproduction - https://github.com/mkilpatrick/vite-ssr-react-base/tree/url-space. Start up the server and go to http://localhost:5173/about vs http://localhost:5173/about%20me.

It's related to inline modules and SSR.

[vite] Internal server error: Cannot read properties of undefined (reading '0')
      at Context.load (file:///Users/mkilpatrick/Desktop/vite-ssr-react-base/node_modules/vite/dist/node/chunks/dep-71eb12cb.js:41067:65)
      at Object.load (file:///Users/mkilpatrick/Desktop/vite-ssr-react-base/node_modules/vite/dist/node/chunks/dep-71eb12cb.js:35260:50)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async loadAndTransform (file:///Users/mkilpatrick/Desktop/vite-ssr-react-base/node_modules/vite/dist/node/chunks/dep-71eb12cb.js:39751:24) (x3)
/@id/__x00__/about%20me?html-proxy&index=0.js
No routes matched location "/@id/__x00__/about%20me?html-proxy&index=0.js"

It's happening in the vite:html-inline-proxy load code.

mkilpatrick avatar Aug 01 '22 20:08 mkilpatrick

It seems there is an inconsistency of filePath. https://github.com/vitejs/vite/blob/937cecc7d89194d8672ab62beb92827f45764c15/packages/vite/src/node/plugins/html.ts#L62-L66 It reproduces with https://github.com/vitejs/vite/issues/9054#issuecomment-1183259223, too.

sapphi-red avatar Aug 02 '22 06:08 sapphi-red