Skip to content

Commit b9eefca

Browse files
Fix Cache Support for [email protected] (#356)
* feat: add cache support for [email protected] * fix: lint files * chore: apply the proposed changes * Fix typo * changeset --------- Co-authored-by: conico974 <[email protected]>
1 parent afd9605 commit b9eefca

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Diff for: .changeset/selfish-suits-exercise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
Fix Cache Support for [email protected]

Diff for: packages/open-next/src/adapters/plugins/14.1/util.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NextConfig } from "../../config";
2+
import { debug } from "../../logger.js";
3+
4+
//#override requestHandler
5+
// @ts-ignore
6+
export const requestHandler = new NextServer.default({
7+
conf: {
8+
...NextConfig,
9+
// Next.js compression should be disabled because of a bug in the bundled
10+
// `compression` package — https://github.com/vercel/next.js/issues/11669
11+
compress: false,
12+
// By default, Next.js uses local disk to store ISR cache. We will use
13+
// our own cache handler to store the cache on S3.
14+
cacheHandler: `${process.env.LAMBDA_TASK_ROOT}/cache.cjs`,
15+
cacheMaxMemorySize: 0,
16+
experimental: {
17+
...NextConfig.experimental,
18+
// This uses the request.headers.host as the URL
19+
// https://github.com/vercel/next.js/blob/canary/packages/next/src/server/next-server.ts#L1749-L1754
20+
trustHostHeader: true,
21+
},
22+
},
23+
customServer: false,
24+
dev: false,
25+
dir: __dirname,
26+
}).getRequestHandler();
27+
//#endOverride
28+
29+
//#override requireHooks
30+
debug("No need to override require hooks with next 13.4.20+");
31+
//#endOverride

Diff for: packages/open-next/src/build.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
673673
: undefined;
674674

675675
if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
676+
const isAfter141 = compareSemver(options.nextVersion, "14.1.0") >= 0;
677+
const utilReplacement = isAfter141 ? "./14.1/util.js" : "./13.5/util.js";
676678
plugins = [
677679
openNextPlugin({
678680
name: "opennext-13.5-serverHandler",
@@ -682,7 +684,10 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
682684
openNextPlugin({
683685
name: "opennext-13.5-util",
684686
target: /plugins\/util\.js/g,
685-
replacements: ["./13.5/util.js", "./util.replacement.js"],
687+
replacements: [
688+
utilReplacement,
689+
...(isAfter141 ? [] : ["./util.replacement.js"]),
690+
],
686691
}),
687692
openNextPlugin({
688693
name: "opennext-13.5-default",

0 commit comments

Comments
 (0)