Skip to content

Commit 1396c7f

Browse files
Fix prerender file locations when cwd differs from project root (#13824)
Co-authored-by: Mark Dalgleish <[email protected]>
1 parent 21fc6e5 commit 1396c7f

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

.changeset/light-pens-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
Fix prerender file locations when `cwd` differs from project root

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
- ken0x0a
196196
- kentcdodds
197197
- kettanaito
198+
- kigawas
198199
- kilavvy
199200
- kiliman
200201
- kkirsche

packages/react-router-dev/vite/plugin.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,7 +2661,7 @@ async function handleSpaMode(
26612661

26622662
// Write out the HTML file for the SPA
26632663
await writeFile(path.join(clientBuildDirectory, filename), html);
2664-
let prettyDir = path.relative(process.cwd(), clientBuildDirectory);
2664+
let prettyDir = path.relative(viteConfig.root, clientBuildDirectory);
26652665
let prettyPath = path.join(prettyDir, filename);
26662666
if (build.prerender.length > 0) {
26672667
viteConfig.logger.info(
@@ -2835,12 +2835,13 @@ async function prerenderData(
28352835
}
28362836

28372837
// Write out the .data file
2838-
let outdir = path.relative(process.cwd(), clientBuildDirectory);
2839-
let outfile = path.join(outdir, ...normalizedPath.split("/"));
2838+
let outfile = path.join(clientBuildDirectory, ...normalizedPath.split("/"));
28402839
await mkdir(path.dirname(outfile), { recursive: true });
28412840
await writeFile(outfile, data);
28422841
viteConfig.logger.info(
2843-
`Prerender (data): ${prerenderPath} -> ${colors.bold(outfile)}`
2842+
`Prerender (data): ${prerenderPath} -> ${colors.bold(
2843+
path.relative(viteConfig.root, outfile)
2844+
)}`
28442845
);
28452846
return data;
28462847
}
@@ -2894,12 +2895,17 @@ async function prerenderRoute(
28942895
}
28952896

28962897
// Write out the HTML file
2897-
let outdir = path.relative(process.cwd(), clientBuildDirectory);
2898-
let outfile = path.join(outdir, ...normalizedPath.split("/"), "index.html");
2898+
let outfile = path.join(
2899+
clientBuildDirectory,
2900+
...normalizedPath.split("/"),
2901+
"index.html"
2902+
);
28992903
await mkdir(path.dirname(outfile), { recursive: true });
29002904
await writeFile(outfile, html);
29012905
viteConfig.logger.info(
2902-
`Prerender (html): ${prerenderPath} -> ${colors.bold(outfile)}`
2906+
`Prerender (html): ${prerenderPath} -> ${colors.bold(
2907+
path.relative(viteConfig.root, outfile)
2908+
)}`
29032909
);
29042910
}
29052911

@@ -2927,12 +2933,13 @@ async function prerenderResourceRoute(
29272933
}
29282934

29292935
// Write out the resource route file
2930-
let outdir = path.relative(process.cwd(), clientBuildDirectory);
2931-
let outfile = path.join(outdir, ...normalizedPath.split("/"));
2936+
let outfile = path.join(clientBuildDirectory, ...normalizedPath.split("/"));
29322937
await mkdir(path.dirname(outfile), { recursive: true });
29332938
await writeFile(outfile, content);
29342939
viteConfig.logger.info(
2935-
`Prerender (resource): ${prerenderPath} -> ${colors.bold(outfile)}`
2940+
`Prerender (resource): ${prerenderPath} -> ${colors.bold(
2941+
path.relative(viteConfig.root, outfile)
2942+
)}`
29362943
);
29372944
}
29382945

0 commit comments

Comments
 (0)