Hydration bugfix
This commit is contained in:
+1
-1
@@ -44,7 +44,7 @@ export default async function grabClientHydrationScript({ page_local_path, }) {
|
||||
txt += ` window.${ClientRootComponentWindowName}.render(component);\n`;
|
||||
txt += `} else {\n`;
|
||||
txt += ` const root = hydrateRoot(document.getElementById("${ClientRootElementIDName}"), component, { onRecoverableError: () => {\n\n`;
|
||||
// txt += ` console.log(\`Hydration Error.\`)\n\n`;
|
||||
txt += ` console.log(\`Hydration Error.\`)\n\n`;
|
||||
txt += ` } });\n\n`;
|
||||
txt += ` window.${ClientRootComponentWindowName} = root;\n`;
|
||||
txt += ` window.__BUNEXT_RERENDER__ = (NewPage) => {\n`;
|
||||
|
||||
+21
-21
@@ -48,34 +48,34 @@ export default async function genWebHTML({ component, pageProps, bundledMap, mod
|
||||
__html: page_hydration_script,
|
||||
}, "data-bunext-head": true })) : null] }), _jsx("body", { children: _jsx("div", { id: ClientRootElementIDName, suppressHydrationWarning: !dev, children: component }) })] }));
|
||||
let html = `<!DOCTYPE html>\n`;
|
||||
// const stream = await renderToReadableStream(final_component, {
|
||||
// onError(error: any) {
|
||||
// if (error.message.includes('unique "key" prop')) return;
|
||||
// console.error(error);
|
||||
// },
|
||||
// });
|
||||
// const htmlBody = await new Response(stream).text();
|
||||
const originalConsole = {
|
||||
log: console.log,
|
||||
warn: console.warn,
|
||||
error: console.error,
|
||||
info: console.info,
|
||||
debug: console.debug,
|
||||
};
|
||||
console.log = () => { };
|
||||
console.warn = () => { };
|
||||
console.error = () => { };
|
||||
console.info = () => { };
|
||||
console.debug = () => { };
|
||||
const stream = await renderToReadableStream(final_component, {
|
||||
onError(error) {
|
||||
if (error.message.includes('unique "key" prop'))
|
||||
return;
|
||||
console.error(error);
|
||||
originalConsole.error(error);
|
||||
},
|
||||
});
|
||||
const htmlBody = await new Response(stream).text();
|
||||
// const originalConsole = {
|
||||
// log: console.log,
|
||||
// warn: console.warn,
|
||||
// error: console.error,
|
||||
// info: console.info,
|
||||
// debug: console.debug,
|
||||
// };
|
||||
// console.log = () => {};
|
||||
// console.warn = () => {};
|
||||
// console.error = () => {};
|
||||
// console.info = () => {};
|
||||
// console.debug = () => {};
|
||||
// const stream = await renderToReadableStream(final_component, {
|
||||
// onError(error: any) {
|
||||
// if (error.message.includes('unique "key" prop')) return;
|
||||
// originalConsole.error(error);
|
||||
// },
|
||||
// });
|
||||
// const htmlBody = await new Response(stream).text();
|
||||
// Object.assign(console, originalConsole);
|
||||
Object.assign(console, originalConsole);
|
||||
html += htmlBody;
|
||||
return html;
|
||||
}
|
||||
|
||||
+12
-2
@@ -5,6 +5,11 @@ import { log } from "../../../utils/log";
|
||||
import grabPageModules from "./grab-page-modules";
|
||||
import grabPageCombinedServerRes from "./grab-page-combined-server-res";
|
||||
class NotFoundError extends Error {
|
||||
status = 404;
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "NotFoundError";
|
||||
}
|
||||
}
|
||||
export default async function grabPageComponent({ req, file_path: passed_file_path, debug, return_server_res_only, }) {
|
||||
const url = req?.url ? new URL(req.url) : undefined;
|
||||
@@ -69,11 +74,16 @@ export default async function grabPageComponent({ req, file_path: passed_file_pa
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
log.error(`Error Grabbing Page Component: ${error.message}`);
|
||||
const is404 = error instanceof NotFoundError ||
|
||||
error?.name === "NotFoundError" ||
|
||||
error?.status === 404;
|
||||
if (!is404) {
|
||||
log.error(`Error Grabbing Page Component: ${error.message}`);
|
||||
}
|
||||
return await grabPageErrorComponent({
|
||||
error,
|
||||
routeParams,
|
||||
is404: error instanceof NotFoundError,
|
||||
is404,
|
||||
url,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@ export default function grabPageReactComponentString({ file_path, root_file_path
|
||||
try {
|
||||
let tsx = ``;
|
||||
const server_res_json = JSON.stringify(EJSON.stringify(server_res || {}) ?? "{}");
|
||||
// Import directly from the source page files. The generated TSX is
|
||||
// bundled before execution, which keeps Root, Page, and any __root
|
||||
// context consumers inside one module graph for SSR.
|
||||
if (root_file_path) {
|
||||
tsx += `import Root from "${root_file_path}"\n`;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import isDevelopment from "../../../utils/is-development";
|
||||
import * as esbuild from "esbuild";
|
||||
import grabDirNames from "../../../utils/grab-dir-names";
|
||||
import path from "path";
|
||||
import tailwindEsbuildPlugin from "./tailwind-esbuild-plugin";
|
||||
export default async function grabTsxStringModule({ tsx, }) {
|
||||
const dev = isDevelopment();
|
||||
const now = Date.now();
|
||||
@@ -29,6 +30,7 @@ export default async function grabTsxStringModule({ tsx, }) {
|
||||
},
|
||||
jsx: "automatic",
|
||||
outfile: target_cache_file_path,
|
||||
plugins: [tailwindEsbuildPlugin],
|
||||
});
|
||||
Loader.registry.delete(target_cache_file_path);
|
||||
const mod = await import(`${target_cache_file_path}?t=${now}`);
|
||||
|
||||
Reference in New Issue
Block a user