Skip to content

Unencoded UTF-8 route breaks build/dev with ssr: false + prerender #13494

Open
@tobigumo

Description

@tobigumo

I'm using React Router as a...

framework

Reproduction

Open the project at https://stackblitz.com/edit/github-z5knh1xo?file=react-router.config.ts
and navigate to /あいう.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @react-router/dev: * => 7.5.2 
    @react-router/node: * => 7.5.2 
    @react-router/serve: * => 7.5.2 
    react-router: * => 7.5.2 
    vite: ^6.0.11 => 6.3.3

Used Package Manager

npm

Expected Behavior

In react-router.config.ts, adjust the prerender array and observe the difference:

  • When "/%E3%81%82%E3%81%84%E3%81%86" (percent-encoded) is listed, no error occurs.
  • When "/あいう" (plain UTF-8) is listed, an error occurs.
import type { Config } from '@react-router/dev/config';

export default {
  ssr: false, // No error occurs when ssr is set to true
  prerender: [
    '/',
    '/abc',
    '/あいう', // triggers the error
    // "/%E3%81%82%E3%81%84%E3%81%86", // safe, percent-encoded
  ],
} satisfies Config;

Error displayed in the browser when running npm run dev

Oops!
Cannot use 'in' operator to search for 'error' in undefined

TypeError: Cannot use 'in' operator to search for 'error' in undefined
    at unwrapSingleFetchResult (https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:7732:15)
    at https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:7550:20
    at async https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:7548:24
    at async https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:5128:19
    at async Promise.all (index 0)
    at async callLoaderOrAction (https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:5141:23)
    at async Promise.all (index 1)
    at async singleFetchLoaderNavigationStrategy (https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:7571:3)
    at async callRouteMiddleware (https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:4894:37)
    at async runMiddlewarePipeline (https://githubz5knh1xo-er5a--5173--d4eba4a9.local-credentialless.webcontainer.io/node_modules/.vite/deps/chunk-4Z2SZVPQ.js?v=ea4a9303:4860:18)

Error displayed in the console when running npm run build

Prerender (data): / -> build/client/_root.data
Prerender (html): / -> build/client/index.html
Prerender (data): /abc -> build/client/abc.data
Prerender (html): /abc -> build/client/abc/index.html
ErrorResponseImpl {
  status: 404,
  statusText: 'Not Found',
  internal: false,
  data: 'Refusing to SSR the path `/%E3%81%82%E3%81%84%E3%81%86` because `ssr:false` is set and the path is not included in the `prerender` config, so in production the path will be a 404.'
}
✗ Build failed in 295ms
[react-router] Prerender (data): Received a 404 status code from `entry.server.tsx` while prerendering the `/あいう` path.
/あいう.data
    at prerenderData (/home/projects/github-z5knh1xo/node_modules/@react-router/dev/dist/vite.js:3850:11)
    at handlePrerender (/home/projects/github-z5knh1xo/node_modules/@react-router/dev/dist/vite.js:3791:16)
    at Object.handler (/home/projects/github-z5knh1xo/node_modules/@react-router/dev/dist/vite.js:3092:13) {
  code: 'PLUGIN_ERROR',
  plugin: 'react-router',
  hook: 'writeBundle'
}

Actual Behavior

Works correctly even with plain UTF-8.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions