From 74d1ea5227c3344ef6702f19d0c23253020824f7 Mon Sep 17 00:00:00 2001 From: spencerHT <1019777269@qq.com> Date: Tue, 7 Nov 2023 11:19:10 +0800 Subject: [PATCH 1/2] feat: add forceCSR for worker server --- packages/server/prod-server/src/workerServer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/server/prod-server/src/workerServer.ts b/packages/server/prod-server/src/workerServer.ts index ef9cb06f0556..1e078ef0a8dd 100644 --- a/packages/server/prod-server/src/workerServer.ts +++ b/packages/server/prod-server/src/workerServer.ts @@ -102,6 +102,9 @@ export type Manifest = { */ pages: Record; routes: ModernRouteInterface[]; + options?: { + forceCSR?: boolean; + }; }; const RESPONSE_NOTFOUND = new ReturnResponse('404: Page not found', 404); @@ -126,7 +129,7 @@ const middlewarePipeline = createAsyncPipeline< export const createHandler = (manifest: Manifest) => { const routeMgr = new RouteMatchManager(); - const { pages, routes } = manifest; + const { pages, routes, options: manifestOpts = {} } = manifest; routeMgr.reset(routes); return async (options: HandlerOptions): Promise => { const { request, loadableStats, routeManifest } = options; @@ -139,6 +142,10 @@ export const createHandler = (manifest: Manifest) => { const entryName = pageMatch.spec.urlPath; const page = pages[entryName]; + if (manifestOpts.forceCSR && url.searchParams.get('csr') === '1') { + return createResponse(page.template); + } + const logger = createLogger({ level: 'warn' }); const metrics = defaultMetrics as any; const reporter = defaultReporter; From 73d161a55e4fe889673c14fe2ea5b9c4c88727b7 Mon Sep 17 00:00:00 2001 From: spencerHT <1019777269@qq.com> Date: Tue, 7 Nov 2023 11:24:11 +0800 Subject: [PATCH 2/2] chore: change --- .changeset/mighty-icons-arrive.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/mighty-icons-arrive.md diff --git a/.changeset/mighty-icons-arrive.md b/.changeset/mighty-icons-arrive.md new file mode 100644 index 000000000000..925f3dbca97f --- /dev/null +++ b/.changeset/mighty-icons-arrive.md @@ -0,0 +1,6 @@ +--- +'@modern-js/prod-server': minor +--- + +feat: add forceCSR options for worker server +feat: 在 worker server 新增 forceCSR 参数和判断 csr=1 降级