Skip to content

Commit

Permalink
chore(server-runtime): refactor isIndexRequestUrl (remix-run#2445)
Browse files Browse the repository at this point in the history
Use `some` vs. an explicit loop with an early return.
  • Loading branch information
donavon authored Sep 3, 2022
1 parent 10cb3cc commit 3d9a72f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,12 @@ async function errorBoundaryError(error: Error, status: number) {
}

function isIndexRequestUrl(url: URL) {
for (let param of url.searchParams.getAll("index")) {
// only use bare `?index` params without a value
// ✅ /foo?index
// ✅ /foo?index&index=123
// ✅ /foo?index=123&index
// ❌ /foo?index=123
if (param === "") {
return true;
}
}

return false;
// only use bare `?index` params without a value
// ✅ /foo?index
// ✅ /foo?index&index=123
// ✅ /foo?index=123&index
// ❌ /foo?index=123
return url.searchParams.getAll("index").some((param) => param === "");
}

function getRequestMatch(url: URL, matches: RouteMatch<ServerRoute>[]) {
Expand Down

0 comments on commit 3d9a72f

Please sign in to comment.