Skip to content

Commit 6dd0473

Browse files
committed
support empty array/string to mean no revalidation
1 parent ce21d77 commit 6dd0473

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

.changeset/hip-weeks-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
support empty array/string to mean no revalidation

src/data/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ cache.clear = () => getCache().clear();
222222

223223
function matchKey(key: string, keys: string[]) {
224224
for (let k of keys) {
225-
if (key.startsWith(k)) return true;
225+
if (k && key.startsWith(k)) return true;
226226
}
227227
return false;
228228
}

src/data/response.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function redirect(url: string, init: number | RouterResponseInit = 302) {
1414

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

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

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

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

0 commit comments

Comments
 (0)