Handle browser Errors.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
import type { LivePageDistGenParams } from "../../../types";
|
||||
export default function genWebHTML({ component, pageProps, bundledMap, head: Head, module, meta, routeParams, debug, }: LivePageDistGenParams): Promise<string>;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { GrabPageComponentRes } from "../../../types";
|
||||
export default function generateWebPageResponseFromComponentReturn({ component, module, bundledMap, head, meta, routeParams, serverRes, debug, }: GrabPageComponentRes): Promise<Response>;
|
||||
@@ -0,0 +1,6 @@
|
||||
type Params = {
|
||||
file_path: string;
|
||||
out_file?: string;
|
||||
};
|
||||
export default function grabFilePathModule<T extends any = any>({ file_path, out_file, }: Params): Promise<T>;
|
||||
export {};
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { GrabPageReactBundledComponentRes } from "../../../types";
|
||||
type Params = {
|
||||
file_path: string;
|
||||
root_file?: string;
|
||||
server_res?: any;
|
||||
};
|
||||
export default function grabPageBundledReactComponent({ file_path, root_file, server_res, }: Params): Promise<GrabPageReactBundledComponentRes | undefined>;
|
||||
export {};
|
||||
@@ -4,13 +4,13 @@ import grabTsxStringModule from "./grab-tsx-string-module";
|
||||
export default async function grabPageBundledReactComponent({ file_path, root_file, server_res, }) {
|
||||
try {
|
||||
let tsx = ``;
|
||||
const server_res_json = EJSON.stringify(server_res || {})?.replace(/"/g, '\\"');
|
||||
const server_res_json = JSON.stringify(EJSON.stringify(server_res || {}) ?? "{}");
|
||||
if (root_file) {
|
||||
tsx += `import Root from "${root_file}"\n`;
|
||||
}
|
||||
tsx += `import Page from "${file_path}"\n`;
|
||||
tsx += `export default function Main() {\n\n`;
|
||||
tsx += `const props = JSON.parse("${server_res_json}")\n\n`;
|
||||
tsx += `const props = JSON.parse(${server_res_json})\n\n`;
|
||||
tsx += ` return (\n`;
|
||||
if (root_file) {
|
||||
tsx += ` <Root suppressHydrationWarning={true} {...props}><Page {...props} /></Root>\n`;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { GrabPageComponentRes } from "../../../types";
|
||||
type Params = {
|
||||
req?: Request;
|
||||
file_path?: string;
|
||||
debug?: boolean;
|
||||
};
|
||||
export default function grabPageComponent({ req, file_path: passed_file_path, debug, }: Params): Promise<GrabPageComponentRes>;
|
||||
export {};
|
||||
+6
-2
@@ -9,6 +9,7 @@ class NotFoundError extends Error {
|
||||
export default async function grabPageComponent({ req, file_path: passed_file_path, debug, }) {
|
||||
const url = req?.url ? new URL(req.url) : undefined;
|
||||
const router = global.ROUTER;
|
||||
const now = Date.now();
|
||||
let routeParams = undefined;
|
||||
try {
|
||||
routeParams = req ? await grabRouteParams({ req }) : undefined;
|
||||
@@ -42,7 +43,7 @@ export default async function grabPageComponent({ req, file_path: passed_file_pa
|
||||
log.info(`bundledMap:`, bundledMap);
|
||||
}
|
||||
const { root_file } = grabRootFile();
|
||||
const module = await import(file_path);
|
||||
const module = await import(`${file_path}?t=${now}`);
|
||||
if (debug) {
|
||||
log.info(`module:`, module);
|
||||
}
|
||||
@@ -68,7 +69,10 @@ export default async function grabPageComponent({ req, file_path: passed_file_pa
|
||||
};
|
||||
try {
|
||||
if (routeParams) {
|
||||
const serverData = await module["server"]?.(routeParams);
|
||||
const serverData = await module["server"]?.({
|
||||
...routeParams,
|
||||
query: { ...routeParams.query, ...match?.query },
|
||||
});
|
||||
return {
|
||||
...serverData,
|
||||
...default_props,
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { BunxRouteParams, GrabPageComponentRes } from "../../../types";
|
||||
type Params = {
|
||||
error?: any;
|
||||
routeParams?: BunxRouteParams;
|
||||
is404?: boolean;
|
||||
};
|
||||
export default function grabPageErrorComponent({ error, routeParams, is404, }: Params): Promise<GrabPageComponentRes>;
|
||||
export {};
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function grabRootFile(): {
|
||||
root_file: string | undefined;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
type Params = {
|
||||
tsx: string;
|
||||
file_path: string;
|
||||
};
|
||||
export default function grabTsxStringModule<T extends any = any>({ tsx, file_path, }: Params): Promise<T>;
|
||||
export {};
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { BunextPageModuleMeta } from "../../../types";
|
||||
type Params = {
|
||||
meta: BunextPageModuleMeta;
|
||||
};
|
||||
export default function grabWebMetaHTML({ meta }: Params): string;
|
||||
export {};
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { BundlerCTXMap } from "../../../types";
|
||||
type Params = {
|
||||
bundledMap?: BundlerCTXMap;
|
||||
};
|
||||
export default function ({ bundledMap }: Params): Promise<string>;
|
||||
export {};
|
||||
@@ -3,8 +3,9 @@ export default async function ({ bundledMap }) {
|
||||
let script = "";
|
||||
script += `console.log(\`Development Environment\`);\n\n`;
|
||||
script += `const hmr = new EventSource("/__hmr");\n`;
|
||||
script += `window.addEventListener("beforeunload", () => hmr.close());\n`;
|
||||
script += `hmr.addEventListener("update", async (event) => {\n`;
|
||||
script += ` if (event.data) {\n`;
|
||||
script += ` if (event?.data) {\n`;
|
||||
script += ` console.log(\`HMR Changes Detected. Updating ...\`);\n`;
|
||||
script += ` try {\n`;
|
||||
script += ` const data = JSON.parse(event.data);\n`;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
type Params = {
|
||||
req: Request;
|
||||
};
|
||||
export default function handleWebPages({ req, }: Params): Promise<Response>;
|
||||
export {};
|
||||
@@ -0,0 +1,3 @@
|
||||
import * as esbuild from "esbuild";
|
||||
declare const tailwindEsbuildPlugin: esbuild.Plugin;
|
||||
export default tailwindEsbuildPlugin;
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { BundlerCTXMap } from "../../../types";
|
||||
type Params = {
|
||||
tsx: string;
|
||||
out_file: string;
|
||||
};
|
||||
export default function writeHMRTsxModule({ tsx, out_file }: Params): Promise<Pick<BundlerCTXMap, "css_path" | "path" | "hash" | "type"> | undefined>;
|
||||
export {};
|
||||
Reference in New Issue
Block a user