Update HMR logic. Refresh on server props update.

This commit is contained in:
2026-03-21 18:03:36 +01:00
parent a504046a36
commit 32056b5cb6
9 changed files with 58 additions and 8 deletions
+3 -3
View File
@@ -5,7 +5,7 @@ import AppNames from "../../utils/grab-app-names";
import grabConstants from "../../utils/grab-constants";
const { PAGES_DIR } = grabDirNames();
export default function grabClientHydrationScript({ page_local_path }) {
const { ClientRootElementIDName, ClientRootComponentWindowName } = grabConstants();
const { ClientRootElementIDName, ClientRootComponentWindowName, ClientWindowPagePropsName, } = grabConstants();
const root_component_path = path.join(PAGES_DIR, `${AppNames["RootPagesComponentName"]}.tsx`);
const does_root_exist = existsSync(root_component_path);
let txt = ``;
@@ -14,7 +14,7 @@ export default function grabClientHydrationScript({ page_local_path }) {
txt += `import Root from "${root_component_path}";\n`;
}
txt += `import Page from "${page_local_path}";\n\n`;
txt += `const pageProps = window.__PAGE_PROPS__ || {};\n`;
txt += `const pageProps = window.${ClientWindowPagePropsName} || {};\n`;
if (does_root_exist) {
txt += `const component = <Root suppressHydrationWarning={true} {...pageProps}><Page {...pageProps} /></Root>\n`;
}
@@ -29,7 +29,7 @@ export default function grabClientHydrationScript({ page_local_path }) {
txt += ` } });\n\n`;
txt += ` window.${ClientRootComponentWindowName} = root;\n`;
txt += ` window.__BUNEXT_RERENDER__ = (NewPage) => {\n`;
txt += ` const props = window.__PAGE_PROPS__ || {};\n`;
txt += ` const props = window.${ClientWindowPagePropsName} || {};\n`;
txt += ` root.render(<NewPage {...props} />);\n`;
txt += ` };\n`;
txt += `}\n`;