Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-pans-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

Fix for Next 15.4+
24 changes: 24 additions & 0 deletions examples/app-router/open-next.config.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";

export default {
default: {
override: {
wrapper: "express-dev",
converter: "node",
incrementalCache: "fs-dev",
queue: "direct",
tagCache: "dummy",
},
},

imageOptimization: {
override: {
wrapper: "dummy",
converter: "dummy",
},
loader: "fs-dev",
},

// You can override the build command here so that you don't have to rebuild next every time you make a change
//buildCommand: "echo 'No build command'",
} satisfies OpenNextConfig;
3 changes: 2 additions & 1 deletion examples/app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.1.24",
"private": true,
"scripts": {
"openbuild": "node ../../packages/open-next/dist/index.js build --streaming --build-command \"npx turbo build\"",
"openbuild": "node ../../packages/open-next/dist/index.js build",
"openbuild:local": "node ../../packages/open-next/dist/index.js build --config-path open-next.config.local.ts",
"dev": "next dev --turbopack --port 3001",
"build": "next build",
"start": "next start --port 3001",
Expand Down
6 changes: 5 additions & 1 deletion examples/app-router/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
"exclude": [
"node_modules",
"open-next.config.ts",
"open-next.config.local.ts"
]
}
22 changes: 22 additions & 0 deletions examples/pages-router/open-next.config.local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
default: {
override: {
wrapper: "express-dev",
converter: "node",
incrementalCache: "fs-dev",
queue: "direct",
tagCache: "dummy",
},
},

imageOptimization: {
override: {
wrapper: "dummy",
converter: "dummy",
},
loader: "fs-dev",
},

// You can override the build command here so that you don't have to rebuild next every time you make a change
//buildCommand: "echo 'No build command'",
};
1 change: 1 addition & 0 deletions examples/pages-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"openbuild": "node ../../packages/open-next/dist/index.js build --build-command \"npx turbo build\"",
"openbuild:local": "node ../../packages/open-next/dist/index.js build --config-path open-next.config.local.ts",
"dev": "next dev --turbopack --port 3002",
"build": "next build",
"start": "next start --port 3002",
Expand Down
7 changes: 7 additions & 0 deletions packages/open-next/src/build/createServerBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ async function generateBundle(
"15.2.0",
);

const isAfter154 = buildHelper.compareSemver(
options.nextVersion,
">=",
"15.4.0",
);

const disableRouting = isBefore13413 || config.middleware?.external;

const updater = new ContentUpdater(options);
Expand All @@ -260,6 +266,7 @@ async function generateBundle(
...(disableRouting ? ["withRouting"] : []),
...(isAfter142 ? ["patchAsyncStorage"] : []),
...(isAfter141 ? ["appendPrefetch"] : []),
...(isAfter154 ? [] : ["setInitialURL"]),
],
}),
openNextReplacementPlugin({
Expand Down
15 changes: 14 additions & 1 deletion packages/open-next/src/core/requestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
constructNextUrl,
convertRes,
convertToQuery,
convertToQueryString,
createServerResponse,
} from "./routing/util";
import routingHandler, {
Expand Down Expand Up @@ -238,7 +239,11 @@ async function processRequest(
// Here we try to apply as much request metadata as possible
// We apply every metadata from `resolve-routes` https://github.com/vercel/next.js/blob/916f105b97211de50f8580f0b39c9e7c60de4886/packages/next/src/server/lib/router-utils/resolve-routes.ts
// and `router-server` https://github.com/vercel/next.js/blob/916f105b97211de50f8580f0b39c9e7c60de4886/packages/next/src/server/lib/router-server.ts
const initialURL = new URL(routingResult.initialURL);
const initialURL = new URL(
// We always assume that only the routing layer can set this header.
routingResult.internalEvent.headers[INTERNAL_HEADER_INITIAL_URL] ??
routingResult.initialURL,
);
let invokeStatus: number | undefined;
if (routingResult.internalEvent.rawPath === "/500") {
invokeStatus = 500;
Expand Down Expand Up @@ -266,6 +271,14 @@ async function processRequest(
//#endOverride

// Next Server
// TODO: only enable this on Next 15.4+
// We need to set the pathname to the data request path
//#override setInitialURL
req.url =
initialURL.pathname +
convertToQueryString(routingResult.internalEvent.query);
//#endOverride

await requestHandler(requestMetadata)(req, res);
} catch (e: any) {
// This might fail when using bundled next, importing won't do the trick either
Expand Down
Loading