MCPcopy
hub / github.com/freshframework/fresh / fetchPartials

Function fetchPartials

packages/fresh/src/runtime/client/partials.ts:353–387  ·  view source on GitHub ↗
(
  actualUrl: URL,
  partialUrl: URL,
  shouldNavigate: boolean,
  init: RequestInit = {},
)

Source from the content-addressed store, hash-verified

351}
352
353async 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
389interface PartialReviveCtx {
390 foundPartials: number;

Callers 1

partials.tsFile · 0.85

Calls 3

applyPartialsFunction · 0.85
maybeReplaceHistoryFunction · 0.85
deleteMethod · 0.45

Tested by

no test coverage detected