diff options
author | 2021-08-17 21:20:34 -0700 | |
---|---|---|
committer | 2021-08-17 21:20:34 -0700 | |
commit | 306c7dda6189521b44253eaf4696eb1ea1b1227f (patch) | |
tree | 444236a2f1ecd05650adffbc5a060a6d7d8ce37c /demos/hello-next/bun-framework-next/client.development.tsx | |
parent | a703afedddfff4f1a4652a234aea199764830c87 (diff) | |
parent | 28cc70cf50398b4b9b6e9ab027b7d965406fba2d (diff) | |
download | bun-306c7dda6189521b44253eaf4696eb1ea1b1227f.tar.gz bun-306c7dda6189521b44253eaf4696eb1ea1b1227f.tar.zst bun-306c7dda6189521b44253eaf4696eb1ea1b1227f.zip |
Merge branch 'main' of github.com:Jarred-Sumner/esdev
Former-commit-id: f4062ec24c4368670a0f5bc336de32fe1df6e821
Diffstat (limited to 'demos/hello-next/bun-framework-next/client.development.tsx')
-rw-r--r-- | demos/hello-next/bun-framework-next/client.development.tsx | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/demos/hello-next/bun-framework-next/client.development.tsx b/demos/hello-next/bun-framework-next/client.development.tsx index c4346913d..aaa505d9c 100644 --- a/demos/hello-next/bun-framework-next/client.development.tsx +++ b/demos/hello-next/bun-framework-next/client.development.tsx @@ -19,6 +19,7 @@ import Router, { hasBasePath, PrivateRouteInfo, } from "next/dist/shared/lib/router/router"; + import { isDynamicRoute } from "next/dist/shared/lib/router/utils/is-dynamic"; import { urlQueryToSearchParams, @@ -33,7 +34,8 @@ import { } from "next/dist/shared/lib/utils"; // import { Portal } from "next/dist/client/portal"; import initHeadManager from "next/dist/client/head-manager"; -import PageLoader, { StyleSheetTuple } from "next/dist/client/page-loader"; +import { HeadManagerContext } from "next/dist/shared/lib/head-manager-context"; +import PageLoader from "./page-loader"; import measureWebVitals from "next/dist/client/performance-relayer"; import { RouteAnnouncer } from "next/dist/client/route-announcer"; import { @@ -97,7 +99,7 @@ if (hasBasePath(asPath)) { asPath = delBasePath(asPath); } -const pageLoader: PageLoader = new PageLoader(buildId, prefix); +const pageLoader: PageLoader = new PageLoader(buildId, prefix, data.pages); const headManager: { mountedInstances: Set<unknown>; @@ -195,14 +197,69 @@ class Container extends React.Component<{ let CachedComponent: React.ComponentType; +const wrapApp = + (App: AppComponent) => + (wrappedAppProps: Record<string, any>): JSX.Element => { + const appProps: AppProps = { + ...wrappedAppProps, + Component: CachedComponent, + err: hydrateErr, + router, + }; + return ( + <AppContainer> + <App {...appProps} /> + </AppContainer> + ); + }; + +function AppContainer({ + children, +}: React.PropsWithChildren<{}>): React.ReactElement { + return ( + <Container fn={(error) => <div>{JSON.stringify(error)}</div>}> + <RouterContext.Provider value={makePublicRouterInstance(router)}> + <HeadManagerContext.Provider value={headManager}> + {children} + </HeadManagerContext.Provider> + </RouterContext.Provider> + </Container> + ); +} + +router = createRouter(page, query, asPath, { + initialProps: hydrateProps, + pageLoader, + App: CachedApp, + Component: CachedComponent, + wrapApp, + err: null, + isFallback: Boolean(isFallback), + subscription: (info, App, scroll) => + render( + Object.assign< + {}, + Omit<RenderRouteInfo, "App" | "scroll">, + Pick<RenderRouteInfo, "App" | "scroll"> + >({}, info, { + App, + scroll, + }) as RenderRouteInfo + ), + locale, + locales, + defaultLocale: "", + domainLocales, + isPreview, +}); + function _boot(EntryPointNamespace) { const PageComponent = EntryPointNamespace.default; ReactDOM.hydrate( - <Container fn={(error) => <div>{JSON.stringify(error)}</div>}> + <AppContainer> <App Component={PageComponent} pageProps={data.props}></App> - </Container>, - + </AppContainer>, document.querySelector("#__next") ); } |