Skip to content

fix: resolve basename/base conflict when basename matches app directory name#15027

Draft
brophdawg11 wants to merge 1 commit intodevfrom
agents/fix-bug-13716
Draft

fix: resolve basename/base conflict when basename matches app directory name#15027
brophdawg11 wants to merge 1 commit intodevfrom
agents/fix-bug-13716

Conversation

@brophdawg11
Copy link
Copy Markdown
Contributor

Fixes #13716

Problem

When Vite's base config and React Router's basename both resolve to the same path segment as the app directory (e.g. base: "/app/", basename: "/app/"), the dev server and build fail with:

Failed to load url /root.tsx (resolved id: /root.tsx) in virtual:react-router/server-build. Does the file exist?

Root cause: resolveFileUrl generates root-relative URLs for route file imports in the virtual server-build module. With appDirectory: "app/" and base: "/app/", it produces /app/root.tsx. During SSR module loading, Vite strips its base prefix from all URLs — turning /app/root.tsx/root.tsx — which doesn't exist.

This was a long-standing issue also present in Remix v2 (remix-run/remix#9382). The existing workaround is to rename the app folder and set appDirectory explicitly — but the framework should handle this transparently.

Fix

In resolveFileUrl, accept an optional publicPath parameter. When the generated root-relative URL starts with the Vite base path, fall back to the /@fs/<absolute-path> form, which bypasses Vite's base-stripping logic.

Pass { publicPath: ctx.publicPath } when calling resolveFileUrl in getServerEntry (for the entry server and all route module imports in the virtual server-build).

Changes

  • packages/react-router-dev/vite/resolve-file-url.ts — added optional publicPath option; uses /@fs/ path when URL would conflict with the Vite base
  • packages/react-router-dev/vite/plugin.ts — passes publicPath to resolveFileUrl in getServerEntry
  • integration/vite-basename-test.ts — adds test cases for base: "/app/" + basename: "/app/" in both dev and build scenarios
  • packages/react-router-dev/.changes/ — changeset

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Preview Build Available

Preview builds have been created for this PR. You can install react-router using:

pnpm install "remix-run/react-router#preview/pr-15027&path:packages/react-router"

And/or install other packages via:

pnpm install "remix-run/react-router#preview/pr-15027&path:packages/react-router-dev"
pnpm install "remix-run/react-router#preview/pr-15027&path:packages/react-router-express"
pnpm install "remix-run/react-router#preview/pr-15027&path:packages/react-router-node"
pnpm install "remix-run/react-router#preview/pr-15027&path:packages/react-router-serve"

These preview builds will be updated automatically as you push new commits.

@brophdawg11 brophdawg11 marked this pull request as draft May 8, 2026 20:14
…ry name

When Vite's `base` config and React Router's `basename` both share
the same path segment as the app directory (e.g. `base: "/app/"`,
`basename: "/app/"`), Vite strips the base prefix from server-build
virtual module import paths during SSR module loading. This caused
"Failed to load url /root.tsx" errors because "/app/root.tsx" was
being resolved to "/root.tsx".

Fix by passing `publicPath` to `resolveFileUrl` when generating
server-build virtual module imports, so that the function falls back to
the `/@fs/` absolute path form when the root-relative URL would
conflict with the Vite base path.

Fixes #13716

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brophdawg11 brophdawg11 changed the base branch from main to dev May 8, 2026 20:20
@brophdawg11 brophdawg11 force-pushed the agents/fix-bug-13716 branch from 1e7be97 to 50bd54b Compare May 8, 2026 20:20
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

✅ Change File Found

A change file file exists in this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use base name of /app/

1 participant