{"version":3,"file":"ssg-client.mjs","sources":["../../../src/client/entries/ClientAppWrapper.tsx","../../../src/client/entries/ssg-client.tsx"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\n/**\n * This is a common wrapper component for csr.tsx and ssg-client.tsx\n */\n\nimport React, { useState } from 'react'\nimport { HashRouter, BrowserRouter } from 'react-router-dom'\nimport { dataCacheCtx, setDataCacheCtx } from '../ctx'\nimport type { PageLoaded } from '../../../clientTypes'\n\n// @ts-expect-error\nconst Router = __HASH_ROUTER__ ? HashRouter : BrowserRouter\n// @ts-expect-error\nconst basename = __HASH_ROUTER__\n  ? undefined\n  : import.meta.env.BASE_URL?.replace(/\\/$/, '')\n\ninterface Props {\n  readonly initCache?: PageLoaded\n  readonly children: React.ReactNode\n}\n\nconst ClientAppWrapper: React.FC<React.PropsWithChildren<Props>> = ({\n  initCache,\n  children,\n}) => {\n  const [dataCache, setDataCache] = useState<PageLoaded>(initCache ?? {})\n  return (\n    <Router basename={basename}>\n      <dataCacheCtx.Provider value={dataCache}>\n        <setDataCacheCtx.Provider value={setDataCache}>\n          {children}\n        </setDataCacheCtx.Provider>\n      </dataCacheCtx.Provider>\n    </Router>\n  )\n}\n\nexport default ClientAppWrapper\n","/**\n * This is the entry for static-site-generation(ssg)'s client side hydration.\n * Used in: \"ssr mode\"\n * (\"ssr\" is used in many places in this project to refer to \"ssg\". Should have called it ssg mode...)\n */\n\nimport React from 'react'\nimport { hydrateRoot } from 'react-dom/client'\n\nimport type { PageLoaded } from '../../../clientTypes'\nimport App from '../App'\nimport ClientAppWrapper from './ClientAppWrapper'\nimport pages from '/@react-pages/pages'\n\ndeclare global {\n  interface Window {\n    _vitePagesSSR: {\n      routePath: string\n    }\n  }\n}\n\nconst routePath = window._vitePagesSSR?.routePath\n\nif (!routePath) {\n  console.error(\n    `[vite-pages]: window._vitePagesSSR?.routePath should be defined`\n  )\n}\n\nconst pageDataImporter = pages[routePath]?.data\nif (pageDataImporter) {\n  // load current page data before hydrate\n  pageDataImporter().then(({ default: pageLoaded }: any) => {\n    const initCache: PageLoaded = {\n      [routePath]: { ...pageLoaded },\n    }\n    hydrate(initCache)\n  })\n} else {\n  // there is no page data for current page\n  hydrate({})\n}\n\nfunction hydrate(initCache: PageLoaded) {\n  const container = document.getElementById('root')!\n  hydrateRoot(\n    container,\n    <ClientAppWrapper initCache={initCache}>\n      <App />\n    </ClientAppWrapper>\n  )\n}\n"],"names":["Router","__HASH_ROUTER__","HashRouter","BrowserRouter","basename","undefined","import","meta","env","BASE_URL","replace","ClientAppWrapper","initCache","children","dataCache","setDataCache","useState","_jsx","dataCacheCtx","Provider","value","setDataCacheCtx","routePath","window","_vitePagesSSR","console","error","pageDataImporter","pages","data","then","default","pageLoaded","hydrate","container","document","getElementById","hydrateRoot","App"],"mappings":";;;;;;;;;;AAAA;;AAWA;AACA,MAAMA,MAAM,GAAGC,eAAe,GAAGC,UAAU,GAAGC,aAAa,CAAA;AAC3D;AACA,MAAMC,QAAQ,GAAGH,eAAe,GAC5BI,SAAS,GACTC,MAAM,CAACC,IAAI,CAACC,GAAG,CAACC,QAAQ,EAAEC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAOhD,MAAMC,gBAA0D,GAAGA,CAAC;EAClEC,SAAS;AACTC,EAAAA,QAAAA;AACF,CAAC,KAAK;AACJ,EAAA,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,QAAQ,CAAaJ,SAAS,IAAI,EAAE,CAAC,CAAA;EACvE,oBACEK,GAAA,CAACjB,MAAM,EAAA;AAACI,IAAAA,QAAQ,EAAEA,QAAS;AAAAS,IAAAA,QAAA,eACzBI,GAAA,CAACC,YAAY,CAACC,QAAQ,EAAA;AAACC,MAAAA,KAAK,EAAEN,SAAU;AAAAD,MAAAA,QAAA,eACtCI,GAAA,CAACI,eAAe,CAACF,QAAQ,EAAA;AAACC,QAAAA,KAAK,EAAEL,YAAa;AAAAF,QAAAA,QAAA,EAC3CA,QAAAA;OACuB,CAA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