fix: resolve basename/base conflict when basename matches app directory name#15027
Draft
brophdawg11 wants to merge 1 commit intodevfrom
Draft
fix: resolve basename/base conflict when basename matches app directory name#15027brophdawg11 wants to merge 1 commit intodevfrom
brophdawg11 wants to merge 1 commit intodevfrom
Conversation
Contributor
Preview Build AvailablePreview builds have been created for this PR. You can install 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. |
…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>
1e7be97 to
50bd54b
Compare
Contributor
✅ Change File FoundA change file file exists in this PR. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13716
Problem
When Vite's
baseconfig and React Router'sbasenameboth resolve to the same path segment as the app directory (e.g.base: "/app/",basename: "/app/"), the dev server and build fail with:Root cause:
resolveFileUrlgenerates root-relative URLs for route file imports in the virtual server-build module. WithappDirectory: "app/"andbase: "/app/", it produces/app/root.tsx. During SSR module loading, Vite strips itsbaseprefix 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
appfolder and setappDirectoryexplicitly — but the framework should handle this transparently.Fix
In
resolveFileUrl, accept an optionalpublicPathparameter. 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 callingresolveFileUrlingetServerEntry(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 optionalpublicPathoption; uses/@fs/path when URL would conflict with the Vite basepackages/react-router-dev/vite/plugin.ts— passespublicPathtoresolveFileUrlingetServerEntryintegration/vite-basename-test.ts— adds test cases forbase: "/app/"+basename: "/app/"in both dev and build scenariospackages/react-router-dev/.changes/— changeset