Skip to content

Commit

Permalink
support empty array/string to mean no revalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Oct 10, 2024
1 parent ce21d77 commit 6dd0473
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-weeks-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/router": patch
---

support empty array/string to mean no revalidation
2 changes: 1 addition & 1 deletion src/data/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ cache.clear = () => getCache().clear();

function matchKey(key: string, keys: string[]) {
for (let k of keys) {
if (key.startsWith(k)) return true;
if (k && key.startsWith(k)) return true;
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/data/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function redirect(url: string, init: number | RouterResponseInit = 302) {

const headers = new Headers(responseInit.headers);
headers.set("Location", url);
revalidate && headers.set("X-Revalidate", revalidate.toString());
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());

const response = new Response(null, {
...responseInit,
Expand All @@ -27,7 +27,7 @@ export function redirect(url: string, init: number | RouterResponseInit = 302) {
export function reload(init: RouterResponseInit = {}) {
const { revalidate, ...responseInit } = init;
const headers = new Headers(responseInit.headers);
revalidate && headers.set("X-Revalidate", revalidate.toString());
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());

return new Response(null, {
...responseInit,
Expand All @@ -38,7 +38,7 @@ export function reload(init: RouterResponseInit = {}) {
export function json<T>(data: T, init: RouterResponseInit = {}) {
const { revalidate, ...responseInit } = init;
const headers = new Headers(responseInit.headers);
revalidate && headers.set("X-Revalidate", revalidate.toString());
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
headers.set("Content-Type", "application/json");

const response = new Response(JSON.stringify(data), {
Expand Down

0 comments on commit 6dd0473

Please sign in to comment.