diff options
author | 2021-08-19 10:45:54 -0700 | |
---|---|---|
committer | 2021-08-19 10:45:54 -0700 | |
commit | f1d3aade3b408ead1c1459eb9e0d90e90290d687 (patch) | |
tree | 789e2cb8b43afc84500681fa472461a66269e5f7 | |
parent | 0826f7710186d7ec26d8d2b284ef8f89186d9350 (diff) | |
download | bun-f1d3aade3b408ead1c1459eb9e0d90e90290d687.tar.gz bun-f1d3aade3b408ead1c1459eb9e0d90e90290d687.tar.zst bun-f1d3aade3b408ead1c1459eb9e0d90e90290d687.zip |
remove unused code in route-loader, fix CSS load promise when loading `/`
Former-commit-id: 2b6a239fb6a5ba735b544949e4a770765887fcf8
-rw-r--r-- | demos/hello-next/bun-framework-next/client.development.tsx | 1 | ||||
-rw-r--r-- | demos/hello-next/bun-framework-next/page-loader.ts | 31 | ||||
-rw-r--r-- | demos/hello-next/bun-framework-next/route-loader.ts | 3 | ||||
-rw-r--r-- | demos/hello-next/pages/index.tsx | 2 |
4 files changed, 23 insertions, 14 deletions
diff --git a/demos/hello-next/bun-framework-next/client.development.tsx b/demos/hello-next/bun-framework-next/client.development.tsx index 24c737b55..86a908bd3 100644 --- a/demos/hello-next/bun-framework-next/client.development.tsx +++ b/demos/hello-next/bun-framework-next/client.development.tsx @@ -323,7 +323,6 @@ export function renderError(e) { globalThis.next = { version: "11.1.0", - router, emitter, render, renderError, diff --git a/demos/hello-next/bun-framework-next/page-loader.ts b/demos/hello-next/bun-framework-next/page-loader.ts index 5674697d9..1d802b41e 100644 --- a/demos/hello-next/bun-framework-next/page-loader.ts +++ b/demos/hello-next/bun-framework-next/page-loader.ts @@ -1,6 +1,6 @@ import NextPageLoader from "next/dist/client/page-loader"; import getAssetPathFromRoute from "next/dist/shared/lib/router/utils/get-asset-path-from-route"; -import createRouteLoader from "./route-loader"; +// import createRouteLoader from "./route-loader"; function insertStyleSheet(url: string) { if (document.querySelector(`link[href="${url}"]`)) { @@ -10,11 +10,11 @@ function insertStyleSheet(url: string) { return new Promise((resolve, reject) => { const link = document.createElement("link"); link.rel = "stylesheet"; - link.href = url; - link.onload = () => void resolve(); + link.onload = () => resolve(); + link.onerror = () => reject(); - link.onerror = () => void reject(); + link.href = url; document.head.appendChild(link); }); } @@ -26,7 +26,7 @@ export default class PageLoader extends NextPageLoader { super(_, __); // TODO: assetPrefix? - this.routeLoader = createRouteLoader(""); + // this.routeLoader = {}; //createRouteLoader(""); // Rewrite the pages object to omit the entry script // At this point, the entry point has been loaded so we don't want to do that again. @@ -60,8 +60,9 @@ export default class PageLoader extends NextPageLoader { cssQueue = []; onImportCSS = (event) => { - this.cssQueue.push(insertStyleSheet(event.detail).then(() => void 0)); + this.cssQueue.push(insertStyleSheet(event.detail)); }; + async loadPage(route: string): Promise<GoodPageCache> { const assets = this.pages[route] || this.pages[getAssetPathFromRoute(route)]; @@ -81,11 +82,19 @@ export default class PageLoader extends NextPageLoader { document.addEventListener("onimportcss", this.onImportCSS, { passive: true, }); + try { const res = await import(src); if (this.cssQueue.length > 0) { await Promise.all(this.cssQueue); + this.cssQueue.length = 0; + } + + document.removeEventListener("onimportcss", this.onImportCSS); + + if (this.cssQueue.length > 0) { + await Promise.all(this.cssQueue); this.cssQueue.length = 0; } @@ -97,10 +106,8 @@ export default class PageLoader extends NextPageLoader { __N_SSG: false, __N_SSP: false, }; - - debugger; } catch (exception) { - debugger; + console.error({ exception }); } // return this.routeLoader.loadRoute(route).then((res) => { @@ -120,7 +127,7 @@ export default class PageLoader extends NextPageLoader { } // not used in development! - prefetch(route: string): Promise<void> { - return this.routeLoader.prefetch(route); - } + // prefetch(route: string): Promise<void> { + // return this.routeLoader.prefetch(route); + // } } diff --git a/demos/hello-next/bun-framework-next/route-loader.ts b/demos/hello-next/bun-framework-next/route-loader.ts index 04714a6fe..75012f82d 100644 --- a/demos/hello-next/bun-framework-next/route-loader.ts +++ b/demos/hello-next/bun-framework-next/route-loader.ts @@ -1,3 +1,4 @@ +<<<<<<< Updated upstream import { ComponentType } from "react"; // import { ClientBuildManifest } from "../build/webpack/plugins/build-manifest-plugin"; import getAssetPathFromRoute from "next/dist/shared/lib/router/utils/get-asset-path-from-route"; @@ -390,3 +391,5 @@ export default function createRouteLoader(assetPrefix: string): RouteLoader { }, }; } +======= +>>>>>>> Stashed changes diff --git a/demos/hello-next/pages/index.tsx b/demos/hello-next/pages/index.tsx index 87ccfd2b3..b87c67a84 100644 --- a/demos/hello-next/pages/index.tsx +++ b/demos/hello-next/pages/index.tsx @@ -20,7 +20,7 @@ export default function Home() { <main className={styles.main}> <h1 className={styles.title}> - apos[ <a href="https://nextjs.org">Next.js!</a> + Welcome to <a href="https://nextjs.org">Next.js!</a> </h1> <p className={styles.description}> |