Skip to content

Commit

Permalink
fix: error header key in other metaName (#4695)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Sep 20, 2023
1 parent 7bc7e9c commit bb97082
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/green-pandas-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/prod-server': patch
---

fix(prod-server): error header key in other metaName
fix(prod-server): 错误的 header key 在不同的 metaName
9 changes: 5 additions & 4 deletions packages/server/prod-server/src/libs/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type CreateRenderHandler = (ctx: {
metaName?: string;
}) => RenderHandler;

const calcFallback = (metaName: string) =>
`x-${cutNameByHyphen(metaName)}-ssr-fallback`;

export const createRenderHandler: CreateRenderHandler = ({
distDir,
staticGenerate,
Expand Down Expand Up @@ -73,9 +76,7 @@ export const createRenderHandler: CreateRenderHandler = ({

// handles ssr first
const useCSR =
forceCSR &&
(ctx.query.csr ||
ctx.headers[`x-${cutNameByHyphen(metaName)}-ssr-fallback`]);
forceCSR && (ctx.query.csr || ctx.headers[calcFallback(metaName)]);
if (route.isSSR && !useCSR) {
try {
const userAgent = ctx.getReqHeader('User-Agent') as string | undefined;
Expand Down Expand Up @@ -129,7 +130,7 @@ export const createRenderHandler: CreateRenderHandler = ({
ERROR_DIGEST.ERENDER,
(err as Error).stack || (err as Error).message,
);
ctx.res.set('x-modern-ssr-fallback', '1');
ctx.res.set(calcFallback(metaName), '1');
}
}

Expand Down

0 comments on commit bb97082

Please sign in to comment.