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
@@ -1,5 +1,6 @@
import _ from "lodash";
import type { BundlerCTXMap, GlobalHMRControllerObject } from "../../types";
import grabPageComponent from "./web-pages/grab-page-component";
type Params = {
artifacts: BundlerCTXMap[];
@@ -21,6 +22,12 @@ export default async function serverPostBuildFn({ artifacts }: Params) {
(a) => controller.target_map?.local_path == a.local_path,
);
const mock_req = new Request(controller.page_url);
const { serverRes } = await grabPageComponent({
req: mock_req,
});
const final_artifact: Omit<GlobalHMRControllerObject, "controller"> = {
..._.omit(controller, ["controller"]),
target_map: target_artifact,
@@ -30,6 +37,10 @@ export default async function serverPostBuildFn({ artifacts }: Params) {
delete final_artifact.target_map;
}
if (serverRes) {
final_artifact.page_props = serverRes;
}
try {
controller.controller.enqueue(
`event: update\ndata: ${JSON.stringify(final_artifact)}\n\n`,