(
actualUrl: URL,
partialUrl: URL,
shouldNavigate: boolean,
init: RequestInit = {},
)
| 351 | } |
| 352 | |
| 353 | async function fetchPartials( |
| 354 | actualUrl: URL, |
| 355 | partialUrl: URL, |
| 356 | shouldNavigate: boolean, |
| 357 | init: RequestInit = {}, |
| 358 | ) { |
| 359 | init.redirect = "follow"; |
| 360 | partialUrl = new URL(partialUrl); |
| 361 | partialUrl.searchParams.set(PARTIAL_SEARCH_PARAM, "true"); |
| 362 | const res = await fetch(partialUrl, init); |
| 363 | |
| 364 | if (res.redirected) { |
| 365 | const nextUrl = new URL(res.url); |
| 366 | if (nextUrl.origin === actualUrl.origin) { |
| 367 | actualUrl = nextUrl; |
| 368 | } |
| 369 | } |
| 370 | actualUrl.searchParams.delete(PARTIAL_SEARCH_PARAM); |
| 371 | |
| 372 | try { |
| 373 | await applyPartials(res); |
| 374 | } catch (err) { |
| 375 | // When a redirect leads to a page without partials, fall back |
| 376 | // to a full page navigation instead of silently failing. |
| 377 | if (err instanceof NoPartialsError && res.redirected) { |
| 378 | location.href = actualUrl.href; |
| 379 | return; |
| 380 | } |
| 381 | throw err; |
| 382 | } |
| 383 | |
| 384 | if (shouldNavigate) { |
| 385 | maybeReplaceHistory(actualUrl); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | interface PartialReviveCtx { |
| 390 | foundPartials: number; |
no test coverage detected