Push HMR updates before the SSR rebuild in dev
Client-only edits are sent to the browser right after the hydration build, without re-running server functions; SSR rebuilds afterwards and props are re-fetched only when a .server.ts output changed or after fullRebuild. Page requests wait for an in-flight SSR rebuild. The SSR build no longer runs Tailwind, the PostCSS processor is reused across rebuilds, and the watcher debounce drops from 200ms to 50ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+34
@@ -1,5 +1,39 @@
|
||||
import _ from "lodash";
|
||||
import grabPageComponent from "./web-pages/grab-page-component";
|
||||
/**
|
||||
* # Push a client-only HMR update
|
||||
* Sends the new client bundle to every controller whose page is in
|
||||
* `changed_pages`, without re-running server functions. The payload carries
|
||||
* no `page_props`, so the browser keeps its current props and only swaps the
|
||||
* hydration script/CSS. Used right after the hydration build so the browser
|
||||
* doesn't wait for the SSR rebuild.
|
||||
*/
|
||||
export function pushClientUpdate(changed_pages) {
|
||||
if (!global.BUNEXT_HMR_CONTROLLERS?.[0] || !global.BUNEXT_BUNDLER_CTX_MAP) {
|
||||
return;
|
||||
}
|
||||
const changed_set = new Set(changed_pages);
|
||||
for (let i = global.BUNEXT_HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
||||
const controller = global.BUNEXT_HMR_CONTROLLERS[i];
|
||||
const local_path = controller?.target_map?.local_path;
|
||||
if (!controller || !local_path || !changed_set.has(local_path)) {
|
||||
continue;
|
||||
}
|
||||
const target_artifact = global.BUNEXT_BUNDLER_CTX_MAP[local_path];
|
||||
const payload = target_artifact?.path
|
||||
? { target_map: target_artifact }
|
||||
: { reload: true };
|
||||
try {
|
||||
controller.controller.enqueue(`event: update\ndata: ${JSON.stringify(payload)}\n\n`);
|
||||
if (target_artifact?.path) {
|
||||
controller.target_map = target_artifact;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
export default async function serverPostBuildFn(params) {
|
||||
if (!global.BUNEXT_HMR_CONTROLLERS?.[0] || !global.BUNEXT_BUNDLER_CTX_MAP) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user