diff options
author | 2021-10-17 15:36:28 -0700 | |
---|---|---|
committer | 2021-10-17 15:36:28 -0700 | |
commit | 9f0ab479b0401f50f703a09d656616653b20eef4 (patch) | |
tree | ff336cb8f4cb6ff8f66a5e17b055bc758644fa87 | |
parent | 884b5e13eefe8dfe930f1f163a7d1759cd2b46a9 (diff) | |
download | bun-9f0ab479b0401f50f703a09d656616653b20eef4.tar.gz bun-9f0ab479b0401f50f703a09d656616653b20eef4.tar.zst bun-9f0ab479b0401f50f703a09d656616653b20eef4.zip |
[bun-framework-next] Fix when the project does not define a `_app` page
-rw-r--r-- | packages/bun-framework-next/client.development.tsx | 18 | ||||
-rw-r--r-- | packages/bun-framework-next/renderDocument.tsx | 4 |
2 files changed, 16 insertions, 6 deletions
diff --git a/packages/bun-framework-next/client.development.tsx b/packages/bun-framework-next/client.development.tsx index 614eb2698..c27f5c660 100644 --- a/packages/bun-framework-next/client.development.tsx +++ b/packages/bun-framework-next/client.development.tsx @@ -12,7 +12,7 @@ React.Children.only = function (children) { }; import * as ReactDOM from "react-dom"; -import App from "next/app"; +import NextApp from "next/app"; import mitt, { MittEmitter } from "next/dist/shared/lib/mitt"; import { RouterContext } from "next/dist/shared/lib/router-context"; import Router, { @@ -23,6 +23,8 @@ import Router, { PrivateRouteInfo, } from "next/dist/shared/lib/router/router"; +const App = NextApp; + import * as NextRouteLoader from "next/dist/client/route-loader"; import { isDynamicRoute } from "next/dist/shared/lib/router/utils/is-dynamic"; import { @@ -188,7 +190,8 @@ const appElement: HTMLElement | null = document.getElementById("__next"); let lastRenderReject: (() => void) | null; let webpackHMR: any; export let router: Router; -let CachedApp: AppComponent, onPerfEntry: (metric: any) => void; +let CachedApp: AppComponent = App, + onPerfEntry: (metric: any) => void; export default function boot(EntryPointNamespace, loader) { _boot(EntryPointNamespace).then(() => {}, false); @@ -311,6 +314,9 @@ export async function _boot(EntryPointNamespace, isError) { const PageComponent = EntryPointNamespace.default; const appScripts = globalThis.__NEXT_DATA__.pages["/_app"]; + + CachedApp = NextApp; + if (appScripts && appScripts.length > 0) { let appSrc; for (let asset of appScripts) { @@ -327,9 +333,9 @@ export async function _boot(EntryPointNamespace, isError) { appSrc + " must have a default export'd React component" ); - CachedApp = AppModule.default; - } else { - CachedApp = App; + if ("default" in AppModule) { + CachedApp = AppModule.default; + } } } @@ -408,7 +414,7 @@ export function renderError(e) { } globalThis.next = { - version: "11.1.0", + version: "11.1.2", emitter, render, renderError, diff --git a/packages/bun-framework-next/renderDocument.tsx b/packages/bun-framework-next/renderDocument.tsx index 795bb7fbc..dfe80c3f7 100644 --- a/packages/bun-framework-next/renderDocument.tsx +++ b/packages/bun-framework-next/renderDocument.tsx @@ -410,6 +410,10 @@ export async function render({ } pages[pathname] = [route.scriptSrc, ...pageStylesheets]; + if (!("/_app" in pages)) { + pages["/_app"] = []; + } + const AppComponent = AppComponent_ || App.default; const Document = (DocumentNamespace && DocumentNamespace.default) || NextDocument.default; |