|
8 | 8 | startTransition |
9 | 9 | } from "solid-js"; |
10 | 10 | import { getRequestEvent, isServer } from "solid-js/web"; |
11 | | -import { useNavigate, getIntent } from "../routing.js"; |
| 11 | +import { useNavigate, getIntent, getInLoadFn } from "../routing.js"; |
12 | 12 | import { CacheEntry } from "../types.js"; |
13 | 13 |
|
14 | 14 | const LocationHeader = "Location"; |
@@ -69,6 +69,7 @@ export function cache<T extends (...args: any) => any>(fn: T, name: string): Cac |
69 | 69 | const cachedFn = ((...args: Parameters<T>) => { |
70 | 70 | const cache = getCache(); |
71 | 71 | const intent = getIntent(); |
| 72 | + const inLoadFn = getInLoadFn(); |
72 | 73 | const owner = getOwner(); |
73 | 74 | const navigate = owner ? useNavigate() : undefined; |
74 | 75 | const now = Date.now(); |
@@ -110,13 +111,13 @@ export function cache<T extends (...args: any) => any>(fn: T, name: string): Cac |
110 | 111 | cached[0] = now; |
111 | 112 | } |
112 | 113 | let res = cached[1]; |
113 | | - if (intent !== "preload") { |
| 114 | + if (!inLoadFn) { |
114 | 115 | res = |
115 | 116 | "then" in cached[1] |
116 | 117 | ? cached[1].then(handleResponse(false), handleResponse(true)) |
117 | 118 | : handleResponse(false)(cached[1]); |
118 | 119 | !isServer && intent === "navigate" && startTransition(() => cached[3][1](cached[0])); // update version |
119 | | - } |
| 120 | + } else "then" in res && res.catch(() => {}); |
120 | 121 | return res; |
121 | 122 | } |
122 | 123 | let res = |
@@ -144,12 +145,12 @@ export function cache<T extends (...args: any) => any>(fn: T, name: string): Cac |
144 | 145 | const e = getRequestEvent(); |
145 | 146 | if (e && e.router!.dataOnly) return (e.router!.data![key] = res); |
146 | 147 | } |
147 | | - if (intent !== "preload") { |
| 148 | + if (!inLoadFn) { |
148 | 149 | res = |
149 | 150 | "then" in res |
150 | 151 | ? res.then(handleResponse(false), handleResponse(true)) |
151 | 152 | : handleResponse(false)(res); |
152 | | - } |
| 153 | + } else "then" in res && res.catch(() => {}); |
153 | 154 | // serialize on server |
154 | 155 | if ( |
155 | 156 | isServer && |
|
0 commit comments