{"version":3,"sources":["../../src/client/page-bootstrap.ts"],"sourcesContent":["import '../lib/require-instrumentation-client'\nimport { hydrate, router } from './'\nimport initOnDemandEntries from './dev/on-demand-entries-client'\nimport { displayContent } from './dev/fouc'\nimport {\n  connectHMR,\n  addMessageListener,\n} from './dev/hot-reloader/pages/websocket'\nimport {\n  assign,\n  urlQueryToSearchParams,\n} from '../shared/lib/router/utils/querystring'\nimport { HMR_ACTIONS_SENT_TO_BROWSER } from '../server/dev/hot-reloader-types'\nimport { RuntimeErrorHandler } from './dev/runtime-error-handler'\nimport { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from './dev/hot-reloader/shared'\nimport { performFullReload } from './dev/hot-reloader/pages/hot-reloader-pages'\nimport { dispatcher } from 'next/dist/compiled/next-devtools'\n\nexport function pageBootstrap(assetPrefix: string) {\n  connectHMR({ assetPrefix, path: '/_next/webpack-hmr' })\n\n  return hydrate({ beforeRender: displayContent }).then(() => {\n    initOnDemandEntries()\n\n    let reloading = false\n\n    addMessageListener((payload) => {\n      if (reloading) return\n      if ('action' in payload) {\n        switch (payload.action) {\n          case HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR: {\n            const { stack, message } = JSON.parse(payload.errorJSON)\n            const error = new Error(message)\n            error.stack = stack\n            throw error\n          }\n          case HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE: {\n            reloading = true\n            window.location.reload()\n            break\n          }\n          case HMR_ACTIONS_SENT_TO_BROWSER.DEV_PAGES_MANIFEST_UPDATE: {\n            fetch(\n              `${assetPrefix}/_next/static/development/_devPagesManifest.json`\n            )\n              .then((res) => res.json())\n              .then((manifest) => {\n                window.__DEV_PAGES_MANIFEST = manifest\n              })\n              .catch((err) => {\n                console.log(`Failed to fetch devPagesManifest`, err)\n              })\n            break\n          }\n          case HMR_ACTIONS_SENT_TO_BROWSER.ADDED_PAGE:\n          case HMR_ACTIONS_SENT_TO_BROWSER.REMOVED_PAGE:\n          case HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES:\n          case HMR_ACTIONS_SENT_TO_BROWSER.SYNC:\n          case HMR_ACTIONS_SENT_TO_BROWSER.BUILT:\n          case HMR_ACTIONS_SENT_TO_BROWSER.BUILDING:\n          case HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE:\n          case HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED:\n          case HMR_ACTIONS_SENT_TO_BROWSER.ISR_MANIFEST:\n          case HMR_ACTIONS_SENT_TO_BROWSER.DEVTOOLS_CONFIG:\n            // Most of these action types are handled in\n            // src/client/dev/hot-reloader/pages/hot-reloader-pages.ts\n            break\n          default:\n            payload satisfies never\n        }\n      } else if ('event' in payload) {\n        switch (payload.event) {\n          case HMR_ACTIONS_SENT_TO_BROWSER.MIDDLEWARE_CHANGES: {\n            return window.location.reload()\n          }\n          case HMR_ACTIONS_SENT_TO_BROWSER.CLIENT_CHANGES: {\n            // This is used in `../server/dev/turbopack-utils.ts`.\n            const isOnErrorPage = window.next.router.pathname === '/_error'\n            // On the error page we want to reload the page when a page was changed\n            if (isOnErrorPage) {\n              if (RuntimeErrorHandler.hadRuntimeError) {\n                console.warn(REACT_REFRESH_FULL_RELOAD_FROM_ERROR)\n              }\n              reloading = true\n              performFullReload(null)\n            }\n            break\n          }\n          case HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ONLY_CHANGES: {\n            if (RuntimeErrorHandler.hadRuntimeError) {\n              console.warn(REACT_REFRESH_FULL_RELOAD_FROM_ERROR)\n              performFullReload(null)\n            }\n\n            const { pages } = payload\n\n            // Make sure to reload when the dev-overlay is showing for an\n            // API route\n            // TODO: Fix `__NEXT_PAGE` type\n            if (pages.includes(router.query.__NEXT_PAGE as string)) {\n              return window.location.reload()\n            }\n\n            if (!router.clc && pages.includes(router.pathname)) {\n              console.log('Refreshing page data due to server-side change')\n              dispatcher.buildingIndicatorShow()\n              const clearIndicator = dispatcher.buildingIndicatorHide\n\n              router\n                .replace(\n                  router.pathname +\n                    '?' +\n                    String(\n                      assign(\n                        urlQueryToSearchParams(router.query),\n                        new URLSearchParams(location.search)\n                      )\n                    ),\n                  router.asPath,\n                  { scroll: false }\n                )\n                .catch(() => {\n                  // trigger hard reload when failing to refresh data\n                  // to show error overlay properly\n                  location.reload()\n                })\n                .finally(clearIndicator)\n            }\n            break\n          }\n          default:\n            payload satisfies never\n        }\n      }\n    })\n  })\n}\n"],"names":["pageBootstrap","assetPrefix","connectHMR","path","hydrate","beforeRender","displayContent","then","initOnDemandEntries","reloading","addMessageListener","payload","action","HMR_ACTIONS_SENT_TO_BROWSER","SERVER_ERROR","stack","message","JSON","parse","errorJSON","error","Error","RELOAD_PAGE","window","location","reload","DEV_PAGES_MANIFEST_UPDATE","fetch","res","json","manifest","__DEV_PAGES_MANIFEST","catch","err","console","log","ADDED_PAGE","REMOVED_PAGE","SERVER_COMPONENT_CHANGES","SYNC","BUILT","BUILDING","TURBOPACK_MESSAGE","TURBOPACK_CONNECTED","ISR_MANIFEST","DEVTOOLS_CONFIG","event","MIDDLEWARE_CHANGES","CLIENT_CHANGES","isOnErrorPage","next","router","pathname","RuntimeErrorHandler","hadRuntimeError","warn","REACT_REFRESH_FULL_RELOAD_FROM_ERROR","performFullReload","SERVER_ONLY_CHANGES","pages","includes","query","__NEXT_PAGE","clc","dispatcher","buildingIndicatorShow","clearIndicator","buildingIndicatorHide","replace","String","assign","urlQueryToSearchParams","URLSearchParams","search","asPath","scroll","finally"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;;QAlBT;kBACyB;gFACA;sBACD;2BAIxB;6BAIA;kCACqC;qCACR;wBACiB;kCACnB;8BACP;AAEpB,SAASA,cAAcC,WAAmB;IAC/CC,IAAAA,qBAAU,EAAC;QAAED;QAAaE,MAAM;IAAqB;IAErD,OAAOC,IAAAA,SAAO,EAAC;QAAEC,cAAcC,oBAAc;IAAC,GAAGC,IAAI,CAAC;QACpDC,IAAAA,8BAAmB;QAEnB,IAAIC,YAAY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