Skip to content

Fix: prendering with basename and ssr:false renders 404s for dynamic routes #13791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 6, 2025

Conversation

skrhlm
Copy link

@skrhlm skrhlm commented Jun 11, 2025

Whenever basename and ssr: false was used together the dynamic urls in the prerender-list (which are without basename) was checked against the normalizedPath, which always has the basename included.

This resulted in that any dynamic urls are considered to become 404s in production, which is a false negative.

fixes #12083, #13615

Copy link

changeset-bot bot commented Jun 11, 2025

🦋 Changeset detected

Latest commit: 811fea8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
react-router Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jun 11, 2025

Hi @skrhlm,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jun 11, 2025

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@skrhlm skrhlm changed the title Fix: prendering with basename and ssr:false Fix: prendering with basename and ssr:false renders 404s for dynamic routes Jun 11, 2025
the normalized (including basename) was compared with  the prerender-entry, which does not have a basename
Comment on lines 178 to 179
if (decodedPathWithoutBasename === "/") {
decodedPathWithoutBasename = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we needed this check because we just add the trailing slash back on below in !_build.prerender.includes(decodedPath + "/")

Comment on lines 175 to 194
if (strippedPath == null) {
// 404 on non-pre-rendered `.data` requests
errorHandler(
new ErrorResponseImpl(
404,
"Not Found",
`Refusing to prerender the \`${decodedPath}\` path because it does ` +
`not start with the basename \`${normalizedBasename}\``,
),
{
context: loadContext,
params,
request,
},
);
return new Response("Not Found", {
status: 404,
statusText: "Not Found",
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a request comes into the dev server without the basename, we can 404 to match what will happen in production

@brophdawg11 brophdawg11 merged commit 41ea498 into remix-run:dev Aug 6, 2025
8 checks passed
Copy link
Contributor

github-actions bot commented Aug 7, 2025

🤖 Hello there,

We just published version 7.8.0-pre.3 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11
Copy link
Contributor

🤖 bad bot - this is not in 7.8.0 and will be in the next release

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.

[Bug]: v7pre - Can't use vite preview with SPA + basename + prerender
2 participants