Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 65ba637

Browse files
committed
fix: dynamic paths should regenerate
1 parent 35cf5ff commit 65ba637

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

packages/libs/lambda-at-edge/src/build.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,6 @@ class Builder {
426426
async buildRegenerationHandler(
427427
buildManifest: OriginRequestDefaultHandlerManifest
428428
): Promise<void> {
429-
// eslint-disable-next-line @typescript-eslint/no-var-requires
430-
const prerenderManifest = require(join(
431-
this.dotNextDir,
432-
"prerender-manifest.json"
433-
));
434429
await Promise.all([
435430
this.copyTraces(buildManifest),
436431
this.processAndCopyHandler(
@@ -442,22 +437,15 @@ class Builder {
442437
join(this.serverlessDir, "pages"),
443438
join(this.outputDir, REGENERATION_LAMBDA_CODE_DIR, "pages"),
444439
{
445-
recursive: true,
446440
filter: (file: string) => {
447441
const isNotPrerenderedHTMLPage = path.extname(file) !== ".html";
448442
const isNotStaticPropsJSONFile = path.extname(file) !== ".json";
449443
const isNotApiPage = pathToPosix(file).indexOf("pages/api") === -1;
450-
const isDirectory = fse.statSync(file).isDirectory();
451-
const isPrerenderedJSFile = this.isPrerenderedJSFile(
452-
prerenderManifest,
453-
path.relative(join(this.serverlessDir, "pages"), file)
454-
);
455444

456445
return (
457-
isNotApiPage &&
458446
isNotPrerenderedHTMLPage &&
459447
isNotStaticPropsJSONFile &&
460-
(isPrerenderedJSFile || isDirectory)
448+
isNotApiPage
461449
);
462450
}
463451
}

packages/libs/lambda-at-edge/src/default-handler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ const handleOriginResponse = async ({
623623
: null;
624624
if (typeof initialRevalidateSeconds === "number" && lastModifiedAt) {
625625
const createdAgo =
626-
// LastModified should always be defined
627626
(Date.now() - (lastModifiedAt.getTime() || Date.now())) / 1000;
628627

629628
const timeToRevalidate = Math.floor(

packages/libs/lambda-at-edge/src/regeneration-handler.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ export const handler: AWSLambda.SQSHandler = async (event) => {
4141
);
4242

4343
const baseKey = cloudFrontEventRequest.uri
44-
.replace(/^\//, "")
4544
.replace(/\.(json|html)$/, "")
4645
.replace(/^_next\/data\/[^\/]*\//, "");
4746

47+
const ssgRoute = manifest.pages.ssg.nonDynamic[baseKey];
48+
const srcPath = ssgRoute.srcRoute || baseKey;
49+
4850
// eslint-disable-next-line @typescript-eslint/no-var-requires
49-
const page = require(`./pages/${baseKey}`);
51+
const page = require(`./pages${srcPath}`);
5052

51-
const jsonKey = `_next/data/${manifest.buildId}/${baseKey}.json`;
52-
const htmlKey = `static-pages/${manifest.buildId}/${baseKey}.html`;
53+
const jsonKey = `_next/data/${manifest.buildId}${baseKey}.json`;
54+
const htmlKey = `static-pages/${manifest.buildId}${baseKey}.html`;
5355

5456
const { renderOpts, html } = await page.renderReqToHTML(
5557
req,

packages/serverless-components/nextjs-cdk-construct/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
9999
{
100100
handler: "index.handler",
101101
runtime: lambda.Runtime.NODEJS_14_X,
102+
timeout: Duration.minutes(1),
102103
code: lambda.Code.fromAsset(
103104
path.join(this.props.serverlessBuildOutDir, "regeneration-lambda")
104105
)

0 commit comments

Comments
 (0)