Bugfix. Update generate-web-html function

This commit is contained in:
Benjamin Toby 2026-03-21 14:05:02 +01:00
parent a38841a587
commit 51db0c447c
8 changed files with 43 additions and 11 deletions

View File

@ -20,9 +20,9 @@ export default function watcher() {
}); });
return; return;
} }
const target_files_match = /\.(tsx?|jsx?|css)$/;
if (event !== "rename") { if (event !== "rename") {
if (filename.match(/\.(tsx?|jsx?|css)$/) && if (filename.match(target_files_match) && global.BUNDLER_CTX) {
global.BUNDLER_CTX) {
if (global.RECOMPILING) if (global.RECOMPILING)
return; return;
global.RECOMPILING = true; global.RECOMPILING = true;
@ -30,7 +30,7 @@ export default function watcher() {
} }
return; return;
} }
if (!filename.match(/\.(tsx?|jsx?)$/)) { if (!filename.match(target_files_match)) {
return; return;
} }
if (!filename.match(/^src\/pages\//)) if (!filename.match(/^src\/pages\//))

View File

@ -1,5 +1,4 @@
import { jsx as _jsx } from "react/jsx-runtime"; import { jsx as _jsx } from "react/jsx-runtime";
import { renderToString } from "react-dom/server";
import grabContants from "../../../utils/grab-constants"; import grabContants from "../../../utils/grab-constants";
import EJSON from "../../../utils/ejson"; import EJSON from "../../../utils/ejson";
import isDevelopment from "../../../utils/is-development"; import isDevelopment from "../../../utils/is-development";
@ -7,11 +6,15 @@ import grabWebPageHydrationScript from "./grab-web-page-hydration-script";
import grabWebMetaHTML from "./grab-web-meta-html"; import grabWebMetaHTML from "./grab-web-meta-html";
import { log } from "../../../utils/log"; import { log } from "../../../utils/log";
import { AppData } from "../../../data/app-data"; import { AppData } from "../../../data/app-data";
import path from "path";
import importReactDomServer from "../../../utils/import-react-dom-server";
export default async function genWebHTML({ component, pageProps, bundledMap, head: Head, module, meta, routeParams, debug, }) { export default async function genWebHTML({ component, pageProps, bundledMap, head: Head, module, meta, routeParams, debug, }) {
const { ClientRootElementIDName, ClientWindowPagePropsName } = grabContants(); const { ClientRootElementIDName, ClientWindowPagePropsName } = grabContants();
if (debug) { if (debug) {
log.info("component", component); log.info("component", component);
} }
const reactDomServer = await importReactDomServer();
const renderToString = reactDomServer.renderToString;
const componentHTML = renderToString(component); const componentHTML = renderToString(component);
if (debug) { if (debug) {
log.info("componentHTML", componentHTML); log.info("componentHTML", componentHTML);

View File

@ -0,0 +1 @@
export default function importReactDomServer(): Promise<any>;

11
dist/utils/import-react-dom-server.js vendored Normal file
View File

@ -0,0 +1,11 @@
import path from "path";
import reactDomServer from "react-dom/server";
export default async function importReactDomServer() {
try {
const reactDomServerDynamicImport = await import(path.join(process.cwd(), "node_modules", "react-dom", "server"));
return reactDomServerDynamicImport;
}
catch (error) {
return reactDomServer;
}
}

View File

@ -27,7 +27,7 @@
], ],
"scripts": { "scripts": {
"dev": "tsc --watch", "dev": "tsc --watch",
"git:push": "bun run test && tsc --noEmit && tsc && git add . && git commit -m 'Major Bugfix. Update init function' && git push", "git:push": "tsc --noEmit && tsc && git add . && git commit -m 'Bugfix. Update generate-web-html function' && git push",
"compile": "bun build ./src/commands/index.ts --compile --outfile bin/bunext", "compile": "bun build ./src/commands/index.ts --compile --outfile bin/bunext",
"build": "tsc", "build": "tsc",
"test": "bun test --max-concurrency=1" "test": "bun test --max-concurrency=1"

View File

@ -27,11 +27,10 @@ export default function watcher() {
return; return;
} }
const target_files_match = /\.(tsx?|jsx?|css)$/;
if (event !== "rename") { if (event !== "rename") {
if ( if (filename.match(target_files_match) && global.BUNDLER_CTX) {
filename.match(/\.(tsx?|jsx?|css)$/) &&
global.BUNDLER_CTX
) {
if (global.RECOMPILING) return; if (global.RECOMPILING) return;
global.RECOMPILING = true; global.RECOMPILING = true;
await global.BUNDLER_CTX.rebuild(); await global.BUNDLER_CTX.rebuild();
@ -39,7 +38,7 @@ export default function watcher() {
return; return;
} }
if (!filename.match(/\.(tsx?|jsx?)$/)) { if (!filename.match(target_files_match)) {
return; return;
} }

View File

@ -1,4 +1,3 @@
import { renderToString } from "react-dom/server";
import grabContants from "../../../utils/grab-constants"; import grabContants from "../../../utils/grab-constants";
import EJSON from "../../../utils/ejson"; import EJSON from "../../../utils/ejson";
import type { LivePageDistGenParams } from "../../../types"; import type { LivePageDistGenParams } from "../../../types";
@ -7,6 +6,8 @@ import grabWebPageHydrationScript from "./grab-web-page-hydration-script";
import grabWebMetaHTML from "./grab-web-meta-html"; import grabWebMetaHTML from "./grab-web-meta-html";
import { log } from "../../../utils/log"; import { log } from "../../../utils/log";
import { AppData } from "../../../data/app-data"; import { AppData } from "../../../data/app-data";
import path from "path";
import importReactDomServer from "../../../utils/import-react-dom-server";
export default async function genWebHTML({ export default async function genWebHTML({
component, component,
@ -25,6 +26,9 @@ export default async function genWebHTML({
log.info("component", component); log.info("component", component);
} }
const reactDomServer = await importReactDomServer();
const renderToString = reactDomServer.renderToString;
const componentHTML = renderToString(component); const componentHTML = renderToString(component);
if (debug) { if (debug) {

View File

@ -0,0 +1,14 @@
import path from "path";
import reactDomServer from "react-dom/server";
export default async function importReactDomServer() {
try {
const reactDomServerDynamicImport = await import(
path.join(process.cwd(), "node_modules", "react-dom", "server")
);
return reactDomServerDynamicImport;
} catch (error) {
return reactDomServer;
}
}