Persist Request accorss hydration refreshes
This commit is contained in:
@@ -4,6 +4,7 @@ import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-resu
|
||||
import pagesSSRContextBundler from "../pages-ssr-context-bundler";
|
||||
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
||||
import apiRoutesContextBundler from "../api-routes-context-bundler";
|
||||
import _ from "lodash";
|
||||
let build_start = 0;
|
||||
let build_starts = 0;
|
||||
const MAX_BUILD_STARTS = 2;
|
||||
@@ -31,7 +32,7 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
||||
const artifact = artifacts[i];
|
||||
if (artifact?.local_path && global.BUNDLER_CTX_MAP) {
|
||||
global.BUNDLER_CTX_MAP[artifact.local_path] =
|
||||
artifact;
|
||||
_.merge(global.BUNDLER_CTX_MAP[artifact.local_path], artifact);
|
||||
}
|
||||
}
|
||||
post_build_fn?.({ artifacts });
|
||||
|
||||
Vendored
+3
-3
@@ -18,13 +18,13 @@ declare global {
|
||||
var LAST_BUILD_TIME: number;
|
||||
var BUNDLER_CTX_MAP: {
|
||||
[k: string]: BundlerCTXMap;
|
||||
} | undefined;
|
||||
};
|
||||
var SSR_BUNDLER_CTX_MAP: {
|
||||
[k: string]: BundlerCTXMap;
|
||||
} | undefined;
|
||||
};
|
||||
var API_ROUTES_BUNDLER_CTX_MAP: {
|
||||
[k: string]: BundlerCTXMap;
|
||||
} | undefined;
|
||||
};
|
||||
var BUNDLER_REBUILDS: 0;
|
||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||
var CURRENT_VERSION: string | undefined;
|
||||
|
||||
-2
@@ -12,10 +12,8 @@ export default async function fullRebuild(params) {
|
||||
global.ROUTER.reload();
|
||||
await global.BUNDLER_CTX?.dispose();
|
||||
global.BUNDLER_CTX = undefined;
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
await global.SSR_BUNDLER_CTX?.dispose();
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
allPagesESBuildContextBundler({
|
||||
post_build_fn: serverPostBuildFn,
|
||||
});
|
||||
|
||||
+4
-1
@@ -14,11 +14,14 @@ export default async function serverPostBuildFn() {
|
||||
continue;
|
||||
}
|
||||
const target_artifact = global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
||||
const mock_req = new Request(controller.page_url);
|
||||
const mock_req = target_artifact.req
|
||||
? target_artifact.req.clone()
|
||||
: new Request(controller.page_url);
|
||||
const { serverRes } = global.IS_SERVER_COMPONENT
|
||||
? await grabPageComponent({
|
||||
req: mock_req,
|
||||
return_server_res_only: true,
|
||||
is_hydration: true,
|
||||
})
|
||||
: {};
|
||||
const final_artifact = {
|
||||
|
||||
@@ -6,6 +6,7 @@ type Params = {
|
||||
retry?: boolean;
|
||||
return_server_res_only?: boolean;
|
||||
skip_server_res?: boolean;
|
||||
is_hydration?: boolean;
|
||||
};
|
||||
export default function grabPageComponent(params: Params): Promise<GrabPageComponentRes>;
|
||||
export {};
|
||||
|
||||
+5
-2
@@ -13,7 +13,7 @@ class NotFoundError extends Error {
|
||||
}
|
||||
}
|
||||
export default async function grabPageComponent(params) {
|
||||
const { req, file_path: passed_file_path, debug, return_server_res_only, skip_server_res, } = params;
|
||||
const { req, file_path: passed_file_path, debug, return_server_res_only, skip_server_res, is_hydration, } = params;
|
||||
const url = req?.url ? new URL(req.url) : undefined;
|
||||
const router = global.ROUTER;
|
||||
let routeParams = undefined;
|
||||
@@ -39,13 +39,16 @@ export default async function grabPageComponent(params) {
|
||||
// log.error(errMsg);
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
const bundledMap = global.BUNDLER_CTX_MAP?.[file_path];
|
||||
const bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||
if (!bundledMap?.path) {
|
||||
console.log(global.BUNDLER_CTX_MAP);
|
||||
const errMsg = `No Bundled File Path for this request path!`;
|
||||
log.error(errMsg);
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
if (req && !is_hydration) {
|
||||
global.BUNDLER_CTX_MAP[file_path].req = req;
|
||||
}
|
||||
if (debug) {
|
||||
log.info(`bundledMap:`, bundledMap);
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -272,6 +272,7 @@ export type BundlerCTXMap = {
|
||||
url_path: string;
|
||||
file_name: string;
|
||||
css_path?: string;
|
||||
req?: Request;
|
||||
};
|
||||
export type GlobalHMRControllerObject = {
|
||||
controller: ReadableStreamDefaultController<string>;
|
||||
|
||||
Reference in New Issue
Block a user