Persist Request accorss hydration refreshes
This commit is contained in:
parent
814a289460
commit
35f7a6fc85
@ -4,6 +4,7 @@ import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-resu
|
|||||||
import pagesSSRContextBundler from "../pages-ssr-context-bundler";
|
import pagesSSRContextBundler from "../pages-ssr-context-bundler";
|
||||||
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
||||||
import apiRoutesContextBundler from "../api-routes-context-bundler";
|
import apiRoutesContextBundler from "../api-routes-context-bundler";
|
||||||
|
import _ from "lodash";
|
||||||
let build_start = 0;
|
let build_start = 0;
|
||||||
let build_starts = 0;
|
let build_starts = 0;
|
||||||
const MAX_BUILD_STARTS = 2;
|
const MAX_BUILD_STARTS = 2;
|
||||||
@ -31,7 +32,7 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
|||||||
const artifact = artifacts[i];
|
const artifact = artifacts[i];
|
||||||
if (artifact?.local_path && global.BUNDLER_CTX_MAP) {
|
if (artifact?.local_path && global.BUNDLER_CTX_MAP) {
|
||||||
global.BUNDLER_CTX_MAP[artifact.local_path] =
|
global.BUNDLER_CTX_MAP[artifact.local_path] =
|
||||||
artifact;
|
_.merge(global.BUNDLER_CTX_MAP[artifact.local_path], artifact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post_build_fn?.({ artifacts });
|
post_build_fn?.({ artifacts });
|
||||||
|
|||||||
6
dist/functions/bunext-init.d.ts
vendored
6
dist/functions/bunext-init.d.ts
vendored
@ -18,13 +18,13 @@ declare global {
|
|||||||
var LAST_BUILD_TIME: number;
|
var LAST_BUILD_TIME: number;
|
||||||
var BUNDLER_CTX_MAP: {
|
var BUNDLER_CTX_MAP: {
|
||||||
[k: string]: BundlerCTXMap;
|
[k: string]: BundlerCTXMap;
|
||||||
} | undefined;
|
};
|
||||||
var SSR_BUNDLER_CTX_MAP: {
|
var SSR_BUNDLER_CTX_MAP: {
|
||||||
[k: string]: BundlerCTXMap;
|
[k: string]: BundlerCTXMap;
|
||||||
} | undefined;
|
};
|
||||||
var API_ROUTES_BUNDLER_CTX_MAP: {
|
var API_ROUTES_BUNDLER_CTX_MAP: {
|
||||||
[k: string]: BundlerCTXMap;
|
[k: string]: BundlerCTXMap;
|
||||||
} | undefined;
|
};
|
||||||
var BUNDLER_REBUILDS: 0;
|
var BUNDLER_REBUILDS: 0;
|
||||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||||
var CURRENT_VERSION: string | undefined;
|
var CURRENT_VERSION: string | undefined;
|
||||||
|
|||||||
2
dist/functions/server/full-rebuild.js
vendored
2
dist/functions/server/full-rebuild.js
vendored
@ -12,10 +12,8 @@ export default async function fullRebuild(params) {
|
|||||||
global.ROUTER.reload();
|
global.ROUTER.reload();
|
||||||
await global.BUNDLER_CTX?.dispose();
|
await global.BUNDLER_CTX?.dispose();
|
||||||
global.BUNDLER_CTX = undefined;
|
global.BUNDLER_CTX = undefined;
|
||||||
global.BUNDLER_CTX_MAP = {};
|
|
||||||
await global.SSR_BUNDLER_CTX?.dispose();
|
await global.SSR_BUNDLER_CTX?.dispose();
|
||||||
global.SSR_BUNDLER_CTX = undefined;
|
global.SSR_BUNDLER_CTX = undefined;
|
||||||
global.SSR_BUNDLER_CTX_MAP = {};
|
|
||||||
allPagesESBuildContextBundler({
|
allPagesESBuildContextBundler({
|
||||||
post_build_fn: serverPostBuildFn,
|
post_build_fn: serverPostBuildFn,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -14,11 +14,14 @@ export default async function serverPostBuildFn() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const target_artifact = global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
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
|
const { serverRes } = global.IS_SERVER_COMPONENT
|
||||||
? await grabPageComponent({
|
? await grabPageComponent({
|
||||||
req: mock_req,
|
req: mock_req,
|
||||||
return_server_res_only: true,
|
return_server_res_only: true,
|
||||||
|
is_hydration: true,
|
||||||
})
|
})
|
||||||
: {};
|
: {};
|
||||||
const final_artifact = {
|
const final_artifact = {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ type Params = {
|
|||||||
retry?: boolean;
|
retry?: boolean;
|
||||||
return_server_res_only?: boolean;
|
return_server_res_only?: boolean;
|
||||||
skip_server_res?: boolean;
|
skip_server_res?: boolean;
|
||||||
|
is_hydration?: boolean;
|
||||||
};
|
};
|
||||||
export default function grabPageComponent(params: Params): Promise<GrabPageComponentRes>;
|
export default function grabPageComponent(params: Params): Promise<GrabPageComponentRes>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class NotFoundError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default async function grabPageComponent(params) {
|
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 url = req?.url ? new URL(req.url) : undefined;
|
||||||
const router = global.ROUTER;
|
const router = global.ROUTER;
|
||||||
let routeParams = undefined;
|
let routeParams = undefined;
|
||||||
@ -39,13 +39,16 @@ export default async function grabPageComponent(params) {
|
|||||||
// log.error(errMsg);
|
// log.error(errMsg);
|
||||||
throw new 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) {
|
if (!bundledMap?.path) {
|
||||||
console.log(global.BUNDLER_CTX_MAP);
|
console.log(global.BUNDLER_CTX_MAP);
|
||||||
const errMsg = `No Bundled File Path for this request path!`;
|
const errMsg = `No Bundled File Path for this request path!`;
|
||||||
log.error(errMsg);
|
log.error(errMsg);
|
||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
}
|
}
|
||||||
|
if (req && !is_hydration) {
|
||||||
|
global.BUNDLER_CTX_MAP[file_path].req = req;
|
||||||
|
}
|
||||||
if (debug) {
|
if (debug) {
|
||||||
log.info(`bundledMap:`, bundledMap);
|
log.info(`bundledMap:`, bundledMap);
|
||||||
}
|
}
|
||||||
|
|||||||
1
dist/types/index.d.ts
vendored
1
dist/types/index.d.ts
vendored
@ -272,6 +272,7 @@ export type BundlerCTXMap = {
|
|||||||
url_path: string;
|
url_path: string;
|
||||||
file_name: string;
|
file_name: string;
|
||||||
css_path?: string;
|
css_path?: string;
|
||||||
|
req?: Request;
|
||||||
};
|
};
|
||||||
export type GlobalHMRControllerObject = {
|
export type GlobalHMRControllerObject = {
|
||||||
controller: ReadableStreamDefaultController<string>;
|
controller: ReadableStreamDefaultController<string>;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"version": "1.0.72",
|
"version": "1.0.73",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-resu
|
|||||||
import pagesSSRContextBundler from "../pages-ssr-context-bundler";
|
import pagesSSRContextBundler from "../pages-ssr-context-bundler";
|
||||||
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
||||||
import apiRoutesContextBundler from "../api-routes-context-bundler";
|
import apiRoutesContextBundler from "../api-routes-context-bundler";
|
||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
let build_start = 0;
|
let build_start = 0;
|
||||||
let build_starts = 0;
|
let build_starts = 0;
|
||||||
@ -50,7 +51,10 @@ export default function esbuildCTXArtifactTracker({
|
|||||||
const artifact = artifacts[i];
|
const artifact = artifacts[i];
|
||||||
if (artifact?.local_path && global.BUNDLER_CTX_MAP) {
|
if (artifact?.local_path && global.BUNDLER_CTX_MAP) {
|
||||||
global.BUNDLER_CTX_MAP[artifact.local_path] =
|
global.BUNDLER_CTX_MAP[artifact.local_path] =
|
||||||
artifact;
|
_.merge(
|
||||||
|
global.BUNDLER_CTX_MAP[artifact.local_path],
|
||||||
|
artifact,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,9 +31,9 @@ declare global {
|
|||||||
var ROUTER: FileSystemRouter;
|
var ROUTER: FileSystemRouter;
|
||||||
var HMR_CONTROLLERS: GlobalHMRControllerObject[];
|
var HMR_CONTROLLERS: GlobalHMRControllerObject[];
|
||||||
var LAST_BUILD_TIME: number;
|
var LAST_BUILD_TIME: number;
|
||||||
var BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap } | undefined;
|
var BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||||
var SSR_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap } | undefined;
|
var SSR_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||||
var API_ROUTES_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap } | undefined;
|
var API_ROUTES_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||||
var BUNDLER_REBUILDS: 0;
|
var BUNDLER_REBUILDS: 0;
|
||||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||||
var CURRENT_VERSION: string | undefined;
|
var CURRENT_VERSION: string | undefined;
|
||||||
|
|||||||
@ -17,11 +17,9 @@ export default async function fullRebuild(params?: { msg?: string }) {
|
|||||||
|
|
||||||
await global.BUNDLER_CTX?.dispose();
|
await global.BUNDLER_CTX?.dispose();
|
||||||
global.BUNDLER_CTX = undefined;
|
global.BUNDLER_CTX = undefined;
|
||||||
global.BUNDLER_CTX_MAP = {};
|
|
||||||
|
|
||||||
await global.SSR_BUNDLER_CTX?.dispose();
|
await global.SSR_BUNDLER_CTX?.dispose();
|
||||||
global.SSR_BUNDLER_CTX = undefined;
|
global.SSR_BUNDLER_CTX = undefined;
|
||||||
global.SSR_BUNDLER_CTX_MAP = {};
|
|
||||||
|
|
||||||
allPagesESBuildContextBundler({
|
allPagesESBuildContextBundler({
|
||||||
post_build_fn: serverPostBuildFn,
|
post_build_fn: serverPostBuildFn,
|
||||||
|
|||||||
@ -24,12 +24,15 @@ export default async function serverPostBuildFn() {
|
|||||||
const target_artifact =
|
const target_artifact =
|
||||||
global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
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
|
const { serverRes } = global.IS_SERVER_COMPONENT
|
||||||
? await grabPageComponent({
|
? await grabPageComponent({
|
||||||
req: mock_req,
|
req: mock_req,
|
||||||
return_server_res_only: true,
|
return_server_res_only: true,
|
||||||
|
is_hydration: true,
|
||||||
})
|
})
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ type Params = {
|
|||||||
retry?: boolean;
|
retry?: boolean;
|
||||||
return_server_res_only?: boolean;
|
return_server_res_only?: boolean;
|
||||||
skip_server_res?: boolean;
|
skip_server_res?: boolean;
|
||||||
|
is_hydration?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function grabPageComponent(
|
export default async function grabPageComponent(
|
||||||
@ -34,6 +35,7 @@ export default async function grabPageComponent(
|
|||||||
debug,
|
debug,
|
||||||
return_server_res_only,
|
return_server_res_only,
|
||||||
skip_server_res,
|
skip_server_res,
|
||||||
|
is_hydration,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const url = req?.url ? new URL(req.url) : undefined;
|
const url = req?.url ? new URL(req.url) : undefined;
|
||||||
@ -72,7 +74,7 @@ export default async function grabPageComponent(
|
|||||||
throw new 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) {
|
if (!bundledMap?.path) {
|
||||||
console.log(global.BUNDLER_CTX_MAP);
|
console.log(global.BUNDLER_CTX_MAP);
|
||||||
@ -81,6 +83,10 @@ export default async function grabPageComponent(
|
|||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req && !is_hydration) {
|
||||||
|
global.BUNDLER_CTX_MAP[file_path].req = req;
|
||||||
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
log.info(`bundledMap:`, bundledMap);
|
log.info(`bundledMap:`, bundledMap);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -310,6 +310,7 @@ export type BundlerCTXMap = {
|
|||||||
url_path: string;
|
url_path: string;
|
||||||
file_name: string;
|
file_name: string;
|
||||||
css_path?: string;
|
css_path?: string;
|
||||||
|
req?: Request;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GlobalHMRControllerObject = {
|
export type GlobalHMRControllerObject = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user