Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/wild-readers-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

Drop the patch for NextServer#getMiddlewareManifest
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { describe, expect, test } from "vitest";

import { computePatchDiff } from "../../utils/test-patch.js";
import {
buildIdRule,
createCacheHandlerRule,
createComposableCacheHandlersRule,
createMiddlewareManifestRule,
} from "./next-server.js";
import { buildIdRule, createCacheHandlerRule, createComposableCacheHandlersRule } from "./next-server.js";

describe("Next Server", () => {
const nextServerCode = `
Expand Down Expand Up @@ -130,38 +125,6 @@ class NextNodeServer extends _baseserver.default {
`);
});

test("middleware manifest", () => {
expect(computePatchDiff("next-server.js", nextServerCode, createMiddlewareManifestRule("manifest")))
.toMatchInlineSnapshot(`
"Index: next-server.js
===================================================================
--- next-server.js
+++ next-server.js
@@ -1,5 +1,4 @@
-
class NextNodeServer extends _baseserver.default {
constructor(options){
// Initialize super class
super(options);
@@ -30,12 +29,10 @@
throw err;
}
}
getMiddlewareManifest() {
- if (this.minimalMode) return null;
- const manifest = require(this.middlewareManifestPath);
- return manifest;
- }
+ return "manifest";
+}
async loadCustomCacheHandlers() {
const { cacheHandlers } = this.nextConfig.experimental;
if (!cacheHandlers) return;
// If we've already initialized the cache handlers interface, don't do it
"
`);
});

test("cache handler", () => {
expect(computePatchDiff("next-server.js", nextServerCode, createCacheHandlerRule("manifest")))
.toMatchInlineSnapshot(`
Expand Down
28 changes: 0 additions & 28 deletions packages/cloudflare/src/cli/build/patches/plugins/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* Note: we will probably need to revisit the patches when the Next adapter API lands
*
* - Inline `getBuildId` as it relies on `readFileSync` that is not supported by workerd
* - Inline the middleware manifest
* - Override the cache and composable cache handlers
*/

import { existsSync, readFileSync } from "node:fs";
import path from "node:path";

import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper.js";
Expand All @@ -31,19 +29,6 @@ export function patchNextServer(updater: ContentUpdater, buildOpts: BuildOptions

contents = patchCode(contents, buildIdRule);

const manifestPath = path.join(
outputDir,
"server-functions/default",
getPackagePath(buildOpts),
".next/server/middleware-manifest.json"
);

const manifest = existsSync(manifestPath)
? JSON.parse(await readFileSync(manifestPath, "utf-8"))
: {};

contents = patchCode(contents, createMiddlewareManifestRule(manifest));

const outputPath = path.join(outputDir, "server-functions/default");
const cacheHandler = path.join(outputPath, getPackagePath(buildOpts), "cache.cjs");
contents = patchCode(contents, createCacheHandlerRule(cacheHandler));
Expand Down Expand Up @@ -72,19 +57,6 @@ fix: |-
}
`;

export function createMiddlewareManifestRule(manifest: unknown) {
return `
rule:
pattern:
selector: method_definition
context: "class { getMiddlewareManifest($$$PARAMS) { $$$_ } }"
fix: |-
getMiddlewareManifest($$$PARAMS) {
return ${JSON.stringify(manifest)};
}
`;
}

/**
* The cache handler used by Next.js is normally defined in the config file as a path. At runtime,
* Next.js would then do a dynamic require on a transformed version of the path to retrieve the
Expand Down