vite ssr - spaces in url leads to different req.pathname
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
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()
);
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.
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
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.
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.