Handle browser Errors.
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
import type { BundlerCTXMap } from "../../types";
|
||||
type Params = {
|
||||
watch?: boolean;
|
||||
exit_after_first_build?: boolean;
|
||||
post_build_fn?: (params: {
|
||||
artifacts: BundlerCTXMap[];
|
||||
}) => Promise<void>;
|
||||
};
|
||||
export default function allPagesBundler(params?: Params): Promise<void>;
|
||||
export {};
|
||||
+2
-1
@@ -56,6 +56,7 @@ export default async function allPagesBundler(params) {
|
||||
}
|
||||
const elapsed = (performance.now() - buildStart).toFixed(0);
|
||||
log.success(`[Built] in ${elapsed}ms`);
|
||||
global.RECOMPILING = false;
|
||||
if (params?.exit_after_first_build) {
|
||||
process.exit();
|
||||
}
|
||||
@@ -84,6 +85,6 @@ export default async function allPagesBundler(params) {
|
||||
await ctx.rebuild();
|
||||
if (params?.watch) {
|
||||
global.BUNDLER_CTX = ctx;
|
||||
global.BUNDLER_CTX.watch();
|
||||
// global.BUNDLER_CTX.watch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as esbuild from "esbuild";
|
||||
import type { BundlerCTXMap, PageFiles } from "../../types";
|
||||
type Params = {
|
||||
result: esbuild.BuildResult<esbuild.BuildOptions>;
|
||||
pages: PageFiles[];
|
||||
};
|
||||
export default function grabArtifactsFromBundledResults({ result, pages, }: Params): BundlerCTXMap[] | undefined;
|
||||
export {};
|
||||
@@ -0,0 +1,5 @@
|
||||
type Params = {
|
||||
page_local_path: string;
|
||||
};
|
||||
export default function grabClientHydrationScript({ page_local_path }: Params): string;
|
||||
export {};
|
||||
+5
-3
@@ -38,15 +38,17 @@ export default function grabClientHydrationScript({ page_local_path }) {
|
||||
// txt += `window.__JSX_RUNTIME__ = JSXRuntime;\n\n`;
|
||||
txt += `const pageProps = window.__PAGE_PROPS__ || {};\n`;
|
||||
if (does_root_exist) {
|
||||
txt += `const component = <Root {...pageProps}><Page {...pageProps} /></Root>\n`;
|
||||
txt += `const component = <Root suppressHydrationWarning={true} {...pageProps}><Page {...pageProps} /></Root>\n`;
|
||||
}
|
||||
else {
|
||||
txt += `const component = <Page {...pageProps} />\n`;
|
||||
txt += `const component = <Page suppressHydrationWarning={true} {...pageProps} />\n`;
|
||||
}
|
||||
txt += `if (window.${ClientRootComponentWindowName}?.render) {\n`;
|
||||
txt += ` window.${ClientRootComponentWindowName}.render(component);\n`;
|
||||
txt += `} else {\n`;
|
||||
txt += ` const root = hydrateRoot(document.getElementById("${ClientRootElementIDName}"), component);\n\n`;
|
||||
txt += ` const root = hydrateRoot(document.getElementById("${ClientRootElementIDName}"), component, { onRecoverableError: () => {\n\n`;
|
||||
txt += ` console.log(\`Hydration Error.\`)\n\n`;
|
||||
txt += ` } });\n\n`;
|
||||
txt += ` window.${ClientRootComponentWindowName} = root;\n`;
|
||||
txt += ` window.__BUNEXT_RERENDER__ = (NewPage) => {\n`;
|
||||
txt += ` const props = window.__PAGE_PROPS__ || {};\n`;
|
||||
|
||||
Reference in New Issue
Block a user