{"version":3,"sources":["../../../src/client/components/layout-router.tsx"],"sourcesContent":["'use client'\n\nimport type { CacheNode } from '../../shared/lib/app-router-types'\nimport type { LoadingModuleData } from '../../shared/lib/app-router-types'\nimport type {\n  FlightRouterState,\n  FlightSegmentPath,\n  Segment,\n} from '../../shared/lib/app-router-types'\nimport type { ErrorComponent } from './error-boundary'\nimport type { FocusAndScrollRef } from './router-reducer/router-reducer-types'\n\nimport React, {\n  Activity,\n  Fragment,\n  useContext,\n  use,\n  Suspense,\n  useDeferredValue,\n  useLayoutEffect,\n  type FragmentInstance,\n  type JSX,\n  type ActivityProps,\n} from 'react'\nimport ReactDOM from 'react-dom'\nimport {\n  LayoutRouterContext,\n  GlobalLayoutRouterContext,\n  TemplateContext,\n} from '../../shared/lib/app-router-context.shared-runtime'\nimport { unresolvedThenable } from './unresolved-thenable'\nimport { ErrorBoundary } from './error-boundary'\nimport { disableSmoothScrollDuringRouteTransition } from '../../shared/lib/router/utils/disable-smooth-scroll'\nimport { RedirectBoundary } from './redirect-boundary'\nimport { HTTPAccessFallbackBoundary } from './http-access-fallback/error-boundary'\nimport {\n  InstantValidationBoundaryContext,\n  RenderValidationBoundaryAtThisLevel,\n} from './instant-validation/boundary'\nimport { createRouterCacheKey } from './router-reducer/create-router-cache-key'\nimport {\n  useRouterBFCache,\n  type RouterBFCacheEntry,\n} from './bfcache-state-manager'\nimport { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'\nimport {\n  NavigationPromisesContext,\n  type NavigationPromises,\n} from '../../shared/lib/hooks-client-context.shared-runtime'\nimport { getParamValueFromCacheKey } from '../route-params'\nimport type { Params } from '../../server/request/params'\nimport { isDeferredRsc } from './router-reducer/ppr-navigations'\n\nconst enableNewScrollHandler = process.env.__NEXT_APP_NEW_SCROLL_HANDLER\n\nconst __DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = (\n  ReactDOM as any\n).__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE\n\n// TODO-APP: Replace with new React API for finding dom nodes without a `ref` when available\n/**\n * Wraps ReactDOM.findDOMNode with additional logic to hide React Strict Mode warning\n */\nfunction findDOMNode(\n  instance: React.ReactInstance | null | undefined\n): Element | Text | null {\n  // Tree-shake for server bundle\n  if (typeof window === 'undefined') return null\n\n  // __DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode is null during module init.\n  // We need to lazily reference it.\n  const internal_reactDOMfindDOMNode =\n    __DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.findDOMNode\n  return internal_reactDOMfindDOMNode(instance)\n}\n\nconst rectProperties = [\n  'bottom',\n  'height',\n  'left',\n  'right',\n  'top',\n  'width',\n  'x',\n  'y',\n] as const\n/**\n * Check if a HTMLElement is hidden or fixed/sticky position\n */\nfunction shouldSkipElement(element: HTMLElement) {\n  // we ignore fixed or sticky positioned elements since they'll likely pass the \"in-viewport\" check\n  // and will result in a situation we bail on scroll because of something like a fixed nav,\n  // even though the actual page content is offscreen\n  if (['sticky', 'fixed'].includes(getComputedStyle(element).position)) {\n    return true\n  }\n\n  // Uses `getBoundingClientRect` to check if the element is hidden instead of `offsetParent`\n  // because `offsetParent` doesn't consider document/body\n  const rect = element.getBoundingClientRect()\n  return rectProperties.every((item) => rect[item] === 0)\n}\n\nconst enum ScrollTargetState {\n  NoClientRects,\n  InViewport,\n  OutOfViewport,\n}\n\n/**\n * Resolve the root scroll padding used by the viewport check.\n *\n * Computed lengths serialize as pixels, but percentages remain relative to\n * the scrollport. Preserve the existing behavior for values that still\n * contain unresolved CSS math.\n */\nfunction getScrollPaddingTopInPixels(\n  htmlElement: HTMLElement,\n  viewportHeight: number\n): number {\n  const scrollPaddingTop = getComputedStyle(htmlElement).scrollPaddingTop\n  const value = Number.parseFloat(scrollPaddingTop)\n\n  if (!Number.isFinite(value) || value < 0) {\n    return 0\n  }\n\n  if (scrollPaddingTop.endsWith('px')) {\n    return value\n  }\n\n  if (scrollPaddingTop.endsWith('%')) {\n    return (value / 100) * viewportHeight\n  }\n\n  return 0\n}\n\n/**\n * Check where the top corner of the HTMLElement is relative to the usable\n * viewport.\n *\n * Scroll padding is resolved lazily so an empty Fragment does not trigger a\n * computed style read. The caller caches the value for the second check.\n */\nfunction getScrollTargetState(\n  instance: HTMLElement | FragmentInstance,\n  viewportHeight: number,\n  getScrollPaddingTop: () => number\n): ScrollTargetState {\n  const rects = instance.getClientRects()\n  if (rects.length === 0) {\n    return ScrollTargetState.NoClientRects\n  }\n  let elementTop = Number.POSITIVE_INFINITY\n  for (let i = 0; i < rects.length; i++) {\n    const rect = rects[i]\n    if (rect.top < elementTop) {\n      elementTop = rect.top\n    }\n  }\n  return elementTop >= getScrollPaddingTop() && elementTop <= viewportHeight\n    ? ScrollTargetState.InViewport\n    : ScrollTargetState.OutOfViewport\n}\n\n/**\n * Find the DOM node for a hash fragment.\n * If `top` the page has to scroll to the top of the page. This mirrors the browser's behavior.\n * If the hash fragment is an id, the page has to scroll to the element with that id.\n * If the hash fragment is a name, the page has to scroll to the first element with that name.\n */\nfunction getHashFragmentDomNode(hashFragment: string) {\n  // If the hash fragment is `top` the page has to scroll to the top of the page.\n  if (hashFragment === 'top') {\n    return document.body\n  }\n\n  // If the hash fragment is an id, the page has to scroll to the element with that id.\n  return (\n    document.getElementById(hashFragment) ??\n    // If the hash fragment is a name, the page has to scroll to the first element with that name.\n    document.getElementsByName(hashFragment)[0] ??\n    null\n  )\n}\ninterface ScrollAndMaybeFocusHandlerProps {\n  focusAndScrollRef: FocusAndScrollRef\n  children: React.ReactNode\n  cacheNode: CacheNode\n}\nclass InnerScrollAndFocusHandlerOld extends React.Component<ScrollAndMaybeFocusHandlerProps> {\n  handlePotentialScroll = () => {\n    // Handle scroll and focus, it's only applied once.\n    const { focusAndScrollRef, cacheNode } = this.props\n\n    const scrollRef = focusAndScrollRef.forceScroll\n      ? focusAndScrollRef.scrollRef\n      : cacheNode.scrollRef\n    if (scrollRef === null || !scrollRef.current) return\n\n    let domNode:\n      | ReturnType<typeof getHashFragmentDomNode>\n      | ReturnType<typeof findDOMNode> = null\n    const hashFragment = focusAndScrollRef.hashFragment\n\n    if (hashFragment) {\n      domNode = getHashFragmentDomNode(hashFragment)\n      if (domNode === null) {\n        // A missing hash target is still a handled scroll intent. Do not\n        // fall back to the route segment or leave the intent pending.\n        scrollRef.current = false\n        focusAndScrollRef.onlyHashChange = false\n        focusAndScrollRef.hashFragment = null\n        return\n      }\n    }\n\n    // `findDOMNode` is tricky because it returns just the first child if the component is a fragment.\n    // This already caused a bug where the first child was a <link/> in head.\n    if (!domNode) {\n      domNode = findDOMNode(this)\n    }\n\n    // If there is no DOM node this layout-router level is skipped. It'll be handled higher-up in the tree.\n    if (!(domNode instanceof Element)) {\n      return\n    }\n\n    // Verify if the element is a HTMLElement and if we want to consider it for scroll behavior.\n    // If the element is skipped, try to select the next sibling and try again.\n    while (!(domNode instanceof HTMLElement) || shouldSkipElement(domNode)) {\n      if (process.env.NODE_ENV !== 'production') {\n        if (domNode.parentElement?.localName === 'head') {\n          // We enter this state when metadata was rendered as part of the page or via Next.js.\n          // This is always a bug in Next.js and caused by React hoisting metadata.\n          // Fixed with `experimental.appNewScrollHandler`\n        }\n      }\n\n      // No siblings found that match the criteria are found, so handle scroll higher up in the tree instead.\n      if (domNode.nextElementSibling === null) {\n        return\n      }\n      domNode = domNode.nextElementSibling\n    }\n\n    // Mark as scrolled so no other segment scrolls for this navigation.\n    scrollRef.current = false\n\n    disableSmoothScrollDuringRouteTransition(\n      () => {\n        // In case of hash scroll, we only need to scroll the element into view\n        if (hashFragment) {\n          domNode.scrollIntoView()\n\n          return\n        }\n        // Store the current viewport height because reading `clientHeight` causes a reflow,\n        // and it won't change during this function.\n        const htmlElement = document.documentElement\n        const viewportHeight = htmlElement.clientHeight\n        let scrollPaddingTop: number | null = null\n        const getScrollPaddingTop = () => {\n          if (scrollPaddingTop === null) {\n            // Reuse the style and layout update from the geometry read above.\n            scrollPaddingTop = getScrollPaddingTopInPixels(\n              htmlElement,\n              viewportHeight\n            )\n          }\n          return scrollPaddingTop\n        }\n\n        // If the element's top edge is already in the viewport, exit early.\n        if (\n          getScrollTargetState(domNode, viewportHeight, getScrollPaddingTop) ===\n          ScrollTargetState.InViewport\n        ) {\n          return\n        }\n\n        // Otherwise, try scrolling go the top of the document to be backward compatible with pages\n        // scrollIntoView() called on `<html/>` element scrolls horizontally on chrome and firefox (that shouldn't happen)\n        // We could use it to scroll horizontally following RTL but that also seems to be broken - it will always scroll left\n        // scrollLeft = 0 also seems to ignore RTL and manually checking for RTL is too much hassle so we will scroll just vertically\n        htmlElement.scrollTop = 0\n\n        // Scroll to domNode if domNode is not in viewport when scrolled to top of document\n        if (\n          getScrollTargetState(domNode, viewportHeight, getScrollPaddingTop) !==\n          ScrollTargetState.InViewport\n        ) {\n          // Scroll into view doesn't scroll horizontally by default when not needed\n          domNode.scrollIntoView()\n        }\n      },\n      {\n        // We will force layout by querying domNode position\n        dontForceLayout: true,\n        onlyHashChange: focusAndScrollRef.onlyHashChange,\n      }\n    )\n\n    // Mutate after scrolling so that it can be read by `disableSmoothScrollDuringRouteTransition`\n    focusAndScrollRef.onlyHashChange = false\n    focusAndScrollRef.hashFragment = null\n\n    // Set focus on the element\n    domNode.focus()\n  }\n\n  componentDidMount() {\n    this.handlePotentialScroll()\n  }\n\n  componentDidUpdate() {\n    this.handlePotentialScroll()\n  }\n\n  render() {\n    return this.props.children\n  }\n}\n\n/**\n * Fork of InnerScrollAndFocusHandlerOld using Fragment refs for scrolling.\n * No longer focuses the first host descendant.\n */\nfunction InnerScrollHandlerNew(props: ScrollAndMaybeFocusHandlerProps) {\n  const childrenRef = React.useRef<FragmentInstance>(null)\n\n  useLayoutEffect(\n    () => {\n      const { focusAndScrollRef, cacheNode } = props\n\n      const scrollRef = focusAndScrollRef.forceScroll\n        ? focusAndScrollRef.scrollRef\n        : cacheNode.scrollRef\n      if (scrollRef === null || !scrollRef.current) return\n\n      let instance: FragmentInstance | HTMLElement | null = null\n      const hashFragment = focusAndScrollRef.hashFragment\n\n      if (hashFragment) {\n        instance = getHashFragmentDomNode(hashFragment)\n        if (instance === null) {\n          // A missing hash target is still a handled scroll intent. Do not\n          // fall back to the route Fragment or leave the intent pending.\n          scrollRef.current = false\n          focusAndScrollRef.onlyHashChange = false\n          focusAndScrollRef.hashFragment = null\n          return\n        }\n      } else {\n        instance = childrenRef.current\n      }\n\n      // If there is no DOM node this layout-router level is skipped. It'll be handled higher-up in the tree.\n      if (instance === null) {\n        return\n      }\n\n      let didHandleScroll = false\n\n      disableSmoothScrollDuringRouteTransition(\n        () => {\n          const htmlElement = document.documentElement\n          let viewportHeight: number | null = null\n          let initialTargetState: ScrollTargetState | null = null\n          let scrollPaddingTop: number | null = null\n          const getScrollPaddingTop = () => {\n            if (scrollPaddingTop === null) {\n              // Reuse the style and layout update from the geometry read.\n              scrollPaddingTop = getScrollPaddingTopInPixels(\n                htmlElement,\n                viewportHeight!\n              )\n            }\n            return scrollPaddingTop\n          }\n\n          if (!hashFragment) {\n            // Store the current viewport height because reading `clientHeight` causes a reflow,\n            // and it won't change during this function.\n            viewportHeight = htmlElement.clientHeight\n            initialTargetState = getScrollTargetState(\n              instance,\n              viewportHeight,\n              getScrollPaddingTop\n            )\n\n            // An empty Fragment is not a scroll target. In particular, avoid\n            // React's sibling fallback and leave the scroll signal available\n            // for another changed segment.\n            if (initialTargetState === ScrollTargetState.NoClientRects) {\n              return\n            }\n          }\n\n          didHandleScroll = true\n\n          // Mark as scrolled so no other segment scrolls for this navigation.\n          scrollRef.current = false\n\n          // This handler intentionally leaves focus untouched; resetting focus on\n          // navigation is deferred.\n\n          // In case of hash scroll, we only need to scroll the element into view\n          if (hashFragment) {\n            instance.scrollIntoView()\n\n            return\n          }\n\n          // If the element's top edge is already in the viewport, exit early.\n          if (initialTargetState === ScrollTargetState.InViewport) {\n            return\n          }\n\n          // Otherwise, try scrolling go the top of the document to be backward compatible with pages\n          // scrollIntoView() called on `<html/>` element scrolls horizontally on chrome and firefox (that shouldn't happen)\n          // We could use it to scroll horizontally following RTL but that also seems to be broken - it will always scroll left\n          // scrollLeft = 0 also seems to ignore RTL and manually checking for RTL is too much hassle so we will scroll just vertically\n          htmlElement.scrollTop = 0\n\n          // Scroll to domNode if domNode is not in viewport when scrolled to top of document\n          if (\n            getScrollTargetState(\n              instance,\n              viewportHeight!,\n              getScrollPaddingTop\n            ) === ScrollTargetState.OutOfViewport\n          ) {\n            // Scroll into view doesn't scroll horizontally by default when not needed\n            instance.scrollIntoView()\n          }\n        },\n        {\n          // We will force layout by querying domNode position\n          dontForceLayout: true,\n          onlyHashChange: focusAndScrollRef.onlyHashChange,\n        }\n      )\n\n      if (!didHandleScroll) {\n        return\n      }\n\n      // Mutate after scrolling so that it can be read by `disableSmoothScrollDuringRouteTransition`\n      focusAndScrollRef.onlyHashChange = false\n      focusAndScrollRef.hashFragment = null\n    },\n    // Used to run on every commit. We may be able to be smarter about this\n    // but be prepared for lots of manual testing.\n    undefined\n  )\n\n  return <Fragment ref={childrenRef}>{props.children}</Fragment>\n}\n\nconst InnerScrollAndMaybeFocusHandler = enableNewScrollHandler\n  ? InnerScrollHandlerNew\n  : InnerScrollAndFocusHandlerOld\n\nfunction ScrollAndMaybeFocusHandler({\n  children,\n  cacheNode,\n}: {\n  children: React.ReactNode\n  cacheNode: CacheNode\n}) {\n  const context = useContext(GlobalLayoutRouterContext)\n  if (!context) {\n    throw new Error('invariant global layout router not mounted')\n  }\n\n  return (\n    <InnerScrollAndMaybeFocusHandler\n      focusAndScrollRef={context.focusAndScrollRef}\n      cacheNode={cacheNode}\n    >\n      {children}\n    </InnerScrollAndMaybeFocusHandler>\n  )\n}\n\n/**\n * InnerLayoutRouter handles rendering the provided segment based on the cache.\n */\nfunction InnerLayoutRouter({\n  tree,\n  segmentPath,\n  debugNameContext,\n  cacheNode: maybeCacheNode,\n  params,\n  url,\n  isActive,\n}: {\n  tree: FlightRouterState\n  segmentPath: FlightSegmentPath\n  debugNameContext: string\n  cacheNode: CacheNode | null\n  params: Params\n  url: string\n  isActive: boolean\n}) {\n  const context = useContext(GlobalLayoutRouterContext)\n  const parentNavPromises = useContext(NavigationPromisesContext)\n\n  if (!context) {\n    throw new Error('invariant global layout router not mounted')\n  }\n\n  const cacheNode =\n    maybeCacheNode !== null\n      ? maybeCacheNode\n      : // This segment is not in the cache. Suspend indefinitely.\n        //\n        // This should only be reachable for inactive/hidden segments, during\n        // prerendering The active segment should always be consistent with the\n        // CacheNode tree. Regardless, if we don't have a matching CacheNode, we\n        // must suspend rather than render nothing, to prevent showing an\n        // inconsistent route.\n\n        (use(unresolvedThenable) as never)\n\n  // `rsc` represents the renderable node for this segment.\n\n  // If this segment has a `prefetchRsc`, it's the statically prefetched data.\n  // We should use that on initial render instead of `rsc`. Then we'll switch\n  // to `rsc` when the dynamic response streams in.\n  //\n  // If no prefetch data is available, then we go straight to rendering `rsc`.\n  const resolvedPrefetchRsc =\n    cacheNode.prefetchRsc !== null ? cacheNode.prefetchRsc : cacheNode.rsc\n\n  // We use `useDeferredValue` to handle switching between the prefetched and\n  // final values. The second argument is returned on initial render, then it\n  // re-renders with the first argument.\n  const rsc: any = useDeferredValue(cacheNode.rsc, resolvedPrefetchRsc)\n\n  // `rsc` is either a React node or a promise for a React node, except we\n  // special case `null` to represent that this segment's data is missing. If\n  // it's a promise, we need to unwrap it so we can determine whether or not the\n  // data is missing.\n  let resolvedRsc: React.ReactNode\n  if (isDeferredRsc(rsc)) {\n    const unwrappedRsc = use(rsc)\n    if (unwrappedRsc === null) {\n      // If the promise was resolved to `null`, it means the data for this\n      // segment was not returned by the server. Suspend indefinitely. When this\n      // happens, the router is responsible for triggering a new state update to\n      // un-suspend this segment.\n      use(unresolvedThenable) as never\n    }\n    resolvedRsc = unwrappedRsc\n  } else {\n    // This is not a deferred RSC promise. Don't need to unwrap it.\n    if (rsc === null) {\n      use(unresolvedThenable) as never\n    }\n    resolvedRsc = rsc\n  }\n\n  // In dev, we create a NavigationPromisesContext containing the instrumented promises that provide\n  // `useSelectedLayoutSegment` and `useSelectedLayoutSegments`.\n  // Promises are cached outside of render to survive suspense retries.\n  let navigationPromises: NavigationPromises | null = null\n  if (process.env.NODE_ENV !== 'production') {\n    const { createNestedLayoutNavigationPromises } =\n      require('./navigation-devtools') as typeof import('./navigation-devtools')\n\n    navigationPromises = createNestedLayoutNavigationPromises(\n      tree,\n      parentNavPromises\n    )\n  }\n\n  let children = resolvedRsc\n\n  if (navigationPromises) {\n    children = (\n      <NavigationPromisesContext.Provider value={navigationPromises}>\n        {resolvedRsc}\n      </NavigationPromisesContext.Provider>\n    )\n  }\n\n  children = (\n    // The layout router context narrows down tree and childNodes at each level.\n    <LayoutRouterContext.Provider\n      value={{\n        parentTree: tree,\n        parentCacheNode: cacheNode,\n        parentSegmentPath: segmentPath,\n        parentParams: params,\n        // This is always set to null as we enter a child segment. It's\n        // populated by LoadingBoundaryProvider the next time we reach a\n        // loading boundary.\n        parentLoadingData: null,\n        debugNameContext: debugNameContext,\n\n        // TODO-APP: overriding of url for parallel routes\n        url: url,\n        isActive: isActive,\n      }}\n    >\n      {children}\n    </LayoutRouterContext.Provider>\n  )\n\n  return children\n}\n\nexport function LoadingBoundaryProvider({\n  loading,\n  children,\n}: {\n  loading: LoadingModuleData\n  children: React.ReactNode\n}) {\n  // Provides the data needed to render a loading.tsx boundary, via context.\n  //\n  // loading.tsx creates a Suspense boundary around each of a layout's child\n  // slots. (Might be bit confusing to think about the data flow, but: if\n  // loading.tsx and layout.tsx are in the same directory, they are assigned\n  // to the same CacheNode.)\n  //\n  // This provider component does not render the Suspense boundary directly;\n  // that's handled by LoadingBoundary.\n  //\n  // TODO: For simplicity, we should combine this provider with LoadingBoundary\n  // and render the Suspense boundary directly. The only real benefit of doing\n  // it separately is so that when there are multiple parallel routes, we only\n  // send the boundary data once, rather than once per child. But that's a\n  // negligible benefit and can be achieved via caching instead.\n  const parentContext = use(LayoutRouterContext)\n  if (parentContext === null) {\n    return children\n  }\n  // All values except for parentLoadingData are the same as the parent context.\n  return (\n    <LayoutRouterContext.Provider\n      value={{\n        parentTree: parentContext.parentTree,\n        parentCacheNode: parentContext.parentCacheNode,\n        parentSegmentPath: parentContext.parentSegmentPath,\n        parentParams: parentContext.parentParams,\n        parentLoadingData: loading,\n        debugNameContext: parentContext.debugNameContext,\n        url: parentContext.url,\n        isActive: parentContext.isActive,\n      }}\n    >\n      {children}\n    </LayoutRouterContext.Provider>\n  )\n}\n\n/**\n * Renders suspense boundary with the provided \"loading\" property as the fallback.\n * If no loading property is provided it renders the children without a suspense boundary.\n */\nfunction LoadingBoundary({\n  name,\n  loading,\n  children,\n}: {\n  name: ActivityProps['name']\n  loading: LoadingModuleData | null\n  children: React.ReactNode\n}): JSX.Element {\n  // TODO: For LoadingBoundary, and the other built-in boundary types, don't\n  // wrap in an extra function component if no user-defined boundary is\n  // provided. In other words, inline this conditional wrapping logic into\n  // the parent component. More efficient and keeps unnecessary junk out of\n  // the component stack.\n  if (loading !== null) {\n    const loadingRsc = loading[0]\n    const loadingStyles = loading[1]\n    const loadingScripts = loading[2]\n    return (\n      <Suspense\n        name={name}\n        fallback={\n          <>\n            {loadingStyles}\n            {loadingScripts}\n            {loadingRsc}\n          </>\n        }\n      >\n        {children}\n      </Suspense>\n    )\n  }\n\n  return <>{children}</>\n}\n\n/**\n * OuterLayoutRouter handles the current segment as well as <Offscreen> rendering of other segments.\n * It can be rendered next to each other with a different `parallelRouterKey`, allowing for Parallel routes.\n */\nexport default function OuterLayoutRouter({\n  parallelRouterKey,\n  error,\n  errorStyles,\n  errorScripts,\n  templateStyles,\n  templateScripts,\n  template,\n  notFound,\n  forbidden,\n  unauthorized,\n  segmentViewBoundaries,\n}: {\n  parallelRouterKey: string\n  error: ErrorComponent | undefined\n  errorStyles: React.ReactNode | undefined\n  errorScripts: React.ReactNode | undefined\n  templateStyles: React.ReactNode | undefined\n  templateScripts: React.ReactNode | undefined\n  template: React.ReactNode\n  notFound: React.ReactNode | undefined\n  forbidden: React.ReactNode | undefined\n  unauthorized: React.ReactNode | undefined\n  segmentViewBoundaries?: React.ReactNode\n}) {\n  const context = useContext(LayoutRouterContext)\n  if (!context) {\n    throw new Error('invariant expected layout router to be mounted')\n  }\n\n  const {\n    parentTree,\n    parentCacheNode,\n    parentSegmentPath,\n    parentParams,\n    parentLoadingData,\n    url,\n    isActive,\n    debugNameContext,\n  } = context\n\n  // Get the CacheNode for this segment by reading it from the parent segment's\n  // child map.\n  const parentTreeSegment = parentTree[0]\n  const segmentPath =\n    parentSegmentPath === null\n      ? // TODO: The root segment value is currently omitted from the segment\n        // path. This has led to a bunch of special cases scattered throughout\n        // the code. We should clean this up.\n        [parallelRouterKey]\n      : parentSegmentPath.concat([parentTreeSegment, parallelRouterKey])\n\n  // The \"state\" key of a segment is the one passed to React — it represents the\n  // identity of the UI tree. Whenever the state key changes, the tree is\n  // recreated and the state is reset. In the App Router model, search params do\n  // not cause state to be lost, so two segments with the same segment path but\n  // different search params should have the same state key.\n  //\n  // The \"cache\" key of a segment, however, *does* include the search params, if\n  // it's possible that the segment accessed the search params on the server.\n  // (This only applies to page segments; layout segments cannot access search\n  // params on the server.)\n  const activeTree = parentTree[1][parallelRouterKey]\n  const maybeParentSlots = parentCacheNode.slots\n  if (activeTree === undefined || maybeParentSlots === null) {\n    // Could not find a matching segment. The client tree is inconsistent with\n    // the server tree. Suspend indefinitely; the router will have already\n    // detected the inconsistency when handling the server response, and\n    // triggered a refresh of the page to recover.\n    use(unresolvedThenable) as never\n  }\n\n  let maybeValidationBoundaryId: string | null = null\n  if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS) {\n    maybeValidationBoundaryId = use(InstantValidationBoundaryContext)\n  }\n\n  const activeSegment = activeTree[0]\n  const activeCacheNode = maybeParentSlots![parallelRouterKey] ?? null\n  const activeStateKey = createRouterCacheKey(activeSegment, true) // no search params\n\n  // At each level of the route tree, not only do we render the currently\n  // active segment — we also render the last N segments that were active at\n  // this level inside a hidden <Activity> boundary, to preserve their state\n  // if or when the user navigates to them again.\n  //\n  // bfcacheEntry is a linked list of FlightRouterStates.\n  let bfcacheEntry: RouterBFCacheEntry | null = useRouterBFCache(\n    activeTree,\n    activeCacheNode,\n    activeStateKey\n  )\n  let children: Array<React.ReactNode> = []\n  do {\n    const tree = bfcacheEntry.tree\n    const cacheNode = bfcacheEntry.cacheNode\n    const stateKey = bfcacheEntry.stateKey\n    const segment = tree[0]\n\n    /*\n    - Error boundary\n      - Only renders error boundary if error component is provided.\n      - Rendered for each segment to ensure they have their own error state.\n      - When gracefully degrade for bots, skip rendering error boundary.\n    - Loading boundary\n      - Only renders suspense boundary if loading components is provided.\n      - Rendered for each segment to ensure they have their own loading state.\n      - Passed to the router during rendering to ensure it can be immediately rendered when suspending on a Flight fetch.\n  */\n\n    let segmentBoundaryTriggerNode: React.ReactNode = null\n    let segmentViewStateNode: React.ReactNode = null\n    if (process.env.NODE_ENV !== 'production') {\n      const { SegmentBoundaryTriggerNode, SegmentViewStateNode } =\n        require('../../next-devtools/userspace/app/segment-explorer-node') as typeof import('../../next-devtools/userspace/app/segment-explorer-node')\n\n      const pagePrefix = normalizeAppPath(url)\n      segmentViewStateNode = (\n        <SegmentViewStateNode key={pagePrefix} page={pagePrefix} />\n      )\n\n      segmentBoundaryTriggerNode = (\n        <>\n          <SegmentBoundaryTriggerNode />\n        </>\n      )\n    }\n\n    let params = parentParams\n    if (Array.isArray(segment)) {\n      // This segment contains a route param. Accumulate these as we traverse\n      // down the router tree. The result represents the set of params that\n      // the layout/page components are permitted to access below this point.\n      const paramName = segment[0]\n      const paramCacheKey = segment[1]\n      const paramType = segment[2]\n      const paramValue = getParamValueFromCacheKey(paramCacheKey, paramType)\n      if (paramValue !== null) {\n        params = {\n          ...parentParams,\n          [paramName]: paramValue,\n        }\n      }\n    }\n\n    const debugName = getBoundaryDebugNameFromSegment(segment)\n    // `debugNameContext` represents the nearest non-\"virtual\" parent segment.\n    // `getBoundaryDebugNameFromSegment` returns undefined for virtual segments.\n    // So if `debugName` is undefined, the context is passed through unchanged.\n    const childDebugNameContext = debugName ?? debugNameContext\n\n    // In practical terms, clicking this name in the Suspense DevTools\n    // should select the child slots of that layout.\n    //\n    // So the name we apply to the Activity boundary is actually based on\n    // the nearest parent segments.\n    //\n    // We skip over \"virtual\" parents, i.e. ones inserted by Next.js that\n    // don't correspond to application-defined code.\n    const isVirtual = debugName === undefined\n    const debugNameToDisplay = isVirtual ? undefined : debugNameContext\n\n    let templateValue = (\n      <ScrollAndMaybeFocusHandler cacheNode={cacheNode}>\n        <ErrorBoundary\n          errorComponent={error}\n          errorStyles={errorStyles}\n          errorScripts={errorScripts}\n        >\n          <LoadingBoundary\n            name={debugNameToDisplay}\n            // TODO: The loading module data for a segment is stored on the\n            // parent, then applied to each of that parent segment's\n            // parallel route slots. In the simple case where there's only\n            // one parallel route (the `children` slot), this is no\n            // different from if the loading module data were stored on the\n            // child directly. But I'm not sure this actually makes sense\n            // when there are multiple parallel routes. It's not a huge\n            // issue because you always have the option to define a narrower\n            // loading boundary for a particular slot. But this sort of\n            // smells like an implementation accident to me.\n            loading={parentLoadingData}\n          >\n            <HTTPAccessFallbackBoundary\n              notFound={notFound}\n              forbidden={forbidden}\n              unauthorized={unauthorized}\n            >\n              <RedirectBoundary>\n                <InnerLayoutRouter\n                  url={url}\n                  tree={tree}\n                  params={params}\n                  cacheNode={cacheNode}\n                  segmentPath={segmentPath}\n                  debugNameContext={childDebugNameContext}\n                  isActive={isActive && stateKey === activeStateKey}\n                />\n                {segmentBoundaryTriggerNode}\n              </RedirectBoundary>\n            </HTTPAccessFallbackBoundary>\n          </LoadingBoundary>\n        </ErrorBoundary>\n        {segmentViewStateNode}\n      </ScrollAndMaybeFocusHandler>\n    )\n\n    if (\n      typeof window === 'undefined' &&\n      process.env.__NEXT_CACHE_COMPONENTS &&\n      typeof maybeValidationBoundaryId === 'string'\n    ) {\n      templateValue = (\n        <RenderValidationBoundaryAtThisLevel id={maybeValidationBoundaryId}>\n          {templateValue}\n        </RenderValidationBoundaryAtThisLevel>\n      )\n    }\n\n    let child = (\n      <TemplateContext.Provider key={stateKey} value={templateValue}>\n        {templateStyles}\n        {templateScripts}\n        {template}\n      </TemplateContext.Provider>\n    )\n\n    if (process.env.NODE_ENV !== 'production') {\n      const { SegmentStateProvider } =\n        require('../../next-devtools/userspace/app/segment-explorer-node') as typeof import('../../next-devtools/userspace/app/segment-explorer-node')\n\n      child = (\n        <SegmentStateProvider key={stateKey}>\n          {child}\n          {segmentViewBoundaries}\n        </SegmentStateProvider>\n      )\n    }\n\n    if (process.env.__NEXT_CACHE_COMPONENTS) {\n      child = (\n        <Activity\n          name={debugNameToDisplay}\n          key={stateKey}\n          mode={stateKey === activeStateKey ? 'visible' : 'hidden'}\n        >\n          {child}\n        </Activity>\n      )\n    }\n\n    children.push(child)\n\n    bfcacheEntry = bfcacheEntry.next\n  } while (bfcacheEntry !== null)\n\n  return children\n}\n\nfunction getBoundaryDebugNameFromSegment(segment: Segment): string | undefined {\n  if (segment === '/') {\n    // Reached the root\n    return '/'\n  }\n  if (typeof segment === 'string') {\n    if (isVirtualLayout(segment)) {\n      return undefined\n    } else {\n      return segment + '/'\n    }\n  }\n  const paramCacheKey = segment[1]\n  return paramCacheKey + '/'\n}\n\nfunction isVirtualLayout(segment: string): boolean {\n  return (\n    // This is inserted by the loader. Uses double-underscore convention\n    // (like __PAGE__ and __DEFAULT__) to avoid collisions with\n    // user-defined route groups.\n    segment === '(__SLOT__)'\n  )\n}\n"],"names":["LoadingBoundaryProvider","OuterLayoutRouter","enableNewScrollHandler","process","env","__NEXT_APP_NEW_SCROLL_HANDLER","__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE","ReactDOM","findDOMNode","instance","window","internal_reactDOMfindDOMNode","rectProperties","shouldSkipElement","element","includes","getComputedStyle","position","rect","getBoundingClientRect","every","item","getScrollPaddingTopInPixels","htmlElement","viewportHeight","scrollPaddingTop","value","Number","parseFloat","isFinite","endsWith","getScrollTargetState","getScrollPaddingTop","rects","getClientRects","length","elementTop","POSITIVE_INFINITY","i","top","getHashFragmentDomNode","hashFragment","document","body","getElementById","getElementsByName","InnerScrollAndFocusHandlerOld","React","Component","componentDidMount","handlePotentialScroll","componentDidUpdate","render","props","children","focusAndScrollRef","cacheNode","scrollRef","forceScroll","current","domNode","onlyHashChange","Element","HTMLElement","NODE_ENV","parentElement","localName","nextElementSibling","disableSmoothScrollDuringRouteTransition","scrollIntoView","documentElement","clientHeight","scrollTop","dontForceLayout","focus","InnerScrollHandlerNew","childrenRef","useRef","useLayoutEffect","didHandleScroll","initialTargetState","undefined","Fragment","ref","InnerScrollAndMaybeFocusHandler","ScrollAndMaybeFocusHandler","context","useContext","GlobalLayoutRouterContext","Error","InnerLayoutRouter","tree","segmentPath","debugNameContext","maybeCacheNode","params","url","isActive","parentNavPromises","NavigationPromisesContext","use","unresolvedThenable","resolvedPrefetchRsc","prefetchRsc","rsc","useDeferredValue","resolvedRsc","isDeferredRsc","unwrappedRsc","navigationPromises","createNestedLayoutNavigationPromises","require","Provider","LayoutRouterContext","parentTree","parentCacheNode","parentSegmentPath","parentParams","parentLoadingData","loading","parentContext","LoadingBoundary","name","loadingRsc","loadingStyles","loadingScripts","Suspense","fallback","parallelRouterKey","error","errorStyles","errorScripts","templateStyles","templateScripts","template","notFound","forbidden","unauthorized","segmentViewBoundaries","parentTreeSegment","concat","activeTree","maybeParentSlots","slots","maybeValidationBoundaryId","__NEXT_CACHE_COMPONENTS","InstantValidationBoundaryContext","activeSegment","activeCacheNode","activeStateKey","createRouterCacheKey","bfcacheEntry","useRouterBFCache","stateKey","segment","segmentBoundaryTriggerNode","segmentViewStateNode","SegmentBoundaryTriggerNode","SegmentViewStateNode","pagePrefix","normalizeAppPath","page","Array","isArray","paramName","paramCacheKey","paramType","paramValue","getParamValueFromCacheKey","debugName","getBoundaryDebugNameFromSegment","childDebugNameContext","isVirtual","debugNameToDisplay","templateValue","ErrorBoundary","errorComponent","HTTPAccessFallbackBoundary","RedirectBoundary","RenderValidationBoundaryAtThisLevel","id","child","TemplateContext","SegmentStateProvider","Activity","mode","push","next","isVirtualLayout"],"mappings":"AAAA;;;;;;;;;;;;;;;;IAumBgBA,uBAAuB;eAAvBA;;IAsFhB;;;CAGC,GACD,OAiQC;eAjQuBC;;;;;;iEA1qBjB;mEACc;+CAKd;oCAC4B;+BACL;qCAC2B;kCACxB;gCACU;0BAIpC;sCAC8B;qCAI9B;0BAC0B;iDAI1B;6BACmC;gCAEZ;AAE9B,MAAMC,yBAAyBC,QAAQC,GAAG,CAACC,6BAA6B;AAExE,MAAMC,+DAA+D,AACnEC,iBAAQ,CACRD,4DAA4D;AAE9D,4FAA4F;AAC5F;;CAEC,GACD,SAASE,YACPC,QAAgD;IAEhD,+BAA+B;IAC/B,IAAI,OAAOC,WAAW,aAAa,OAAO;IAE1C,uGAAuG;IACvG,kCAAkC;IAClC,MAAMC,+BACJL,6DAA6DE,WAAW;IAC1E,OAAOG,6BAA6BF;AACtC;AAEA,MAAMG,iBAAiB;IACrB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AACD;;CAEC,GACD,SAASC,kBAAkBC,OAAoB;IAC7C,kGAAkG;IAClG,0FAA0F;IAC1F,mDAAmD;IACnD,IAAI;QAAC;QAAU;KAAQ,CAACC,QAAQ,CAACC,iBAAiBF,SAASG,QAAQ,GAAG;QACpE,OAAO;IACT;IAEA,2FAA2F;IAC3F,wDAAwD;IACxD,MAAMC,OAAOJ,QAAQK,qBAAqB;IAC1C,OAAOP,eAAeQ,KAAK,CAAC,CAACC,OAASH,IAAI,CAACG,KAAK,KAAK;AACvD;AAQA;;;;;;CAMC,GACD,SAASC,4BACPC,WAAwB,EACxBC,cAAsB;IAEtB,MAAMC,mBAAmBT,iBAAiBO,aAAaE,gBAAgB;IACvE,MAAMC,QAAQC,OAAOC,UAAU,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