Skip to content

Commit

Permalink
Trim trailing slashes from single fetch data URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Jul 24, 2024
1 parent 2c8eecd commit dfe63e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/large-donkeys-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

Ensure single fetch calls don't include any trailing slash from the pathname (i.e., /path/.data)
8 changes: 7 additions & 1 deletion packages/remix-react/single-fetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,13 @@ export function singleFetchUrl(reqUrl: URL | string) {
typeof reqUrl === "string"
? new URL(reqUrl, window.location.origin)
: reqUrl;
url.pathname = `${url.pathname === "/" ? "_root" : url.pathname}.data`;

if (url.pathname === "/") {
url.pathname = "_root.data";
} else {
url.pathname = `${url.pathname.replace(/\/$/, "")}.data`;
}

return url;
}

Expand Down

0 comments on commit dfe63e7

Please sign in to comment.