Skip to content

Commit d9f19ab

Browse files
authored
Fix window error in PrefetchPageLinks during SSR in Single Fetch (#10601)
1 parent d458dc4 commit d9f19ab

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/tall-mirrors-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/react": patch
3+
---
4+
5+
Fix `window is not defined` error in Single Fetch when server-rendering `<PrefetchPageLinks>`

packages/remix-react/single-fetch.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,14 @@ function stripIndexParam(url: URL) {
381381
export function singleFetchUrl(reqUrl: URL | string) {
382382
let url =
383383
typeof reqUrl === "string"
384-
? new URL(reqUrl, window.location.origin)
384+
? new URL(
385+
reqUrl,
386+
// This can be called during the SSR flow via PrefetchPageLinksImpl so
387+
// don't assume window is available
388+
typeof window === "undefined"
389+
? "server://singlefetch/"
390+
: window.location.origin
391+
)
385392
: reqUrl;
386393

387394
if (url.pathname === "/") {

0 commit comments

Comments
 (0)