From e171af77fe8ed12c91674c9e9f8d779f758cd2eb Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 24 Jul 2024 16:58:05 -0400 Subject: [PATCH] Trim trailing slashes from single fetch data URLs (#9792) --- .changeset/large-donkeys-remember.md | 5 +++++ packages/remix-react/single-fetch.tsx | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/large-donkeys-remember.md diff --git a/.changeset/large-donkeys-remember.md b/.changeset/large-donkeys-remember.md new file mode 100644 index 00000000000..5499280988d --- /dev/null +++ b/.changeset/large-donkeys-remember.md @@ -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) diff --git a/packages/remix-react/single-fetch.tsx b/packages/remix-react/single-fetch.tsx index e6c156efa95..78c2715a7ec 100644 --- a/packages/remix-react/single-fetch.tsx +++ b/packages/remix-react/single-fetch.tsx @@ -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; }