{"version":3,"sources":["../../../../../src/client/components/router-reducer/reducers/refresh-reducer.ts"],"sourcesContent":["import type {\n  ReadonlyReducerState,\n  ReducerState,\n  RefreshAction,\n} from '../router-reducer-types'\nimport { ScrollBehavior } from '../router-reducer-types'\nimport {\n  convertServerPatchToFullTree,\n  navigateToKnownRoute,\n} from '../../segment-cache/navigation'\nimport { invalidateSegmentCacheEntries } from '../../segment-cache/cache'\nimport { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree'\nimport { FreshnessPolicy } from '../ppr-navigations'\nimport {\n  invalidateBfCache,\n  UnknownDynamicStaleTime,\n} from '../../segment-cache/bfcache'\n\nexport function refreshReducer(\n  state: ReadonlyReducerState,\n  action: RefreshAction\n): ReducerState {\n  // During a refresh, we invalidate the segment cache but not the route cache.\n  // The route cache contains the tree structure (which segments exist at a\n  // given URL) which doesn't change during a refresh. The segment cache\n  // contains the actual RSC data which needs to be re-fetched.\n  //\n  // The Instant Navigation Testing API can bypass cache invalidation to\n  // preserve prefetched data when refreshing after an MPA navigation. This is\n  // only used for testing and is not exposed in production builds by default.\n  const bypassCacheInvalidation =\n    process.env.__NEXT_EXPOSE_TESTING_API && action.bypassCacheInvalidation\n  if (!bypassCacheInvalidation) {\n    const currentNextUrl = state.nextUrl\n    const currentRouterState = state.tree\n    invalidateSegmentCacheEntries(currentNextUrl, currentRouterState)\n  }\n  return refreshDynamicData(state, FreshnessPolicy.RefreshAll)\n}\n\nexport function refreshDynamicData(\n  state: ReadonlyReducerState,\n  freshnessPolicy: FreshnessPolicy.RefreshAll | FreshnessPolicy.HMRRefresh\n): ReducerState {\n  // During a refresh, invalidate the BFCache, which may contain dynamic data.\n  invalidateBfCache()\n\n  const currentNextUrl = state.nextUrl\n\n  // We always send the last next-url, not the current when performing a dynamic\n  // request. This is because we update the next-url after a navigation, but we\n  // want the same interception route to be matched that used the last next-url.\n  const nextUrlForRefresh = hasInterceptionRouteInCurrentTree(state.tree)\n    ? state.previousNextUrl || currentNextUrl\n    : null\n\n  // A refresh is modeled as a navigation to the current URL, but where any\n  // existing dynamic data (including in shared layouts) is re-fetched.\n  const currentCanonicalUrl = state.canonicalUrl\n  const currentUrl = new URL(currentCanonicalUrl, location.origin)\n  const currentRenderedSearch = state.renderedSearch\n  const currentFlightRouterState = state.tree\n  const scrollBehavior = ScrollBehavior.NoScroll\n\n  // Create a NavigationSeed from the current FlightRouterState.\n  // TODO: Eventually we will store this type directly on the state object\n  // instead of reconstructing it on demand. Part of a larger series of\n  // refactors to unify the various tree types that the client deals with.\n  const now = Date.now()\n  // TODO: Store the dynamic stale time on the top-level state so it's known\n  // during restores and refreshes.\n  const refreshSeed = convertServerPatchToFullTree(\n    now,\n    currentFlightRouterState,\n    null,\n    currentRenderedSearch,\n    UnknownDynamicStaleTime\n  )\n\n  const navigateType = 'replace'\n  return navigateToKnownRoute(\n    now,\n    state,\n    currentUrl,\n    currentCanonicalUrl,\n    refreshSeed,\n    currentUrl,\n    currentRenderedSearch,\n    state.cache,\n    currentFlightRouterState,\n    freshnessPolicy,\n    nextUrlForRefresh,\n    scrollBehavior,\n    navigateType,\n    null,\n    // Refresh navigations don't use route prediction, so there's no route\n    // cache entry to mark as having a dynamic rewrite on mismatch. If a\n    // mismatch occurs, the retry handler will traverse the known route tree\n    // to find and mark the entry.\n    null\n  )\n}\n"],"names":["refreshDynamicData","refreshReducer","state","action","bypassCacheInvalidation","process","env","__NEXT_EXPOSE_TESTING_API","currentNextUrl","nextUrl","currentRouterState","tree","invalidateSegmentCacheEntries","FreshnessPolicy","RefreshAll","freshnessPolicy","invalidateBfCache","nextUrlForRefresh","hasInterceptionRouteInCurrentTree","previousNextUrl","currentCanonicalUrl","canonicalUrl","currentUrl","URL","location","origin","currentRenderedSearch","renderedSearch","currentFlightRouterState","scrollBehavior","ScrollBehavior","NoScroll","now","Date","refreshSeed","convertServerPatchToFullTree","UnknownDynamicStaleTime","navigateType","navigateToKnownRoute","cache"],"mappings":";;;;;;;;;;;;;;;IAwCgBA,k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