Skip to content
Draft
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
2 changes: 1 addition & 1 deletion examples/e2e/app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"openbuild": "node ../../packages/open-next/dist/index.js build --streaming --build-command \"npx turbo build\"",
"dev": "next dev --turbopack --port 3001",
"build": "next build",
"build": "next build --turbopack",
"start": "next start --port 3001",
"lint": "next lint",
"clean": "rm -rf .turbo node_modules .next .open-next",
Expand Down
7 changes: 1 addition & 6 deletions examples/e2e/experimental/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ const nextConfig: NextConfig = {
/* config options here */
cleanDistDir: true,
output: "standalone",
eslint: {
ignoreDuringBuilds: true,
},
cacheComponents: true,
typescript: {
// Ignore type errors during build for now, we'll need to figure this out later
ignoreBuildErrors: true,
},
experimental: {
cacheComponents: true,
},
};

export default nextConfig;
2 changes: 1 addition & 1 deletion examples/e2e/experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@opennextjs/cloudflare": "workspace:*",
"next": "15.4.2-canary.29",
"next": "16.0.2-canary.13",
"react": "catalog:e2e",
"react-dom": "catalog:e2e"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/experimental/src/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { revalidateTag } from "next/cache";

export function GET() {
revalidateTag("fullyTagged");
revalidateTag("fullyTagged", { expire: 0 });
return new Response("DONE");
}
2 changes: 1 addition & 1 deletion examples/e2e/experimental/src/app/ppr/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DynamicComponent } from "@/components/dynamic";
import { StaticComponent } from "@/components/static";
import { Suspense } from "react";

export const experimental_ppr = true;
// export const experimental_ppr = true;

export default function PPRPage() {
return (
Expand Down
6 changes: 3 additions & 3 deletions examples/e2e/experimental/src/components/cached.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unstable_cacheLife, unstable_cacheTag } from "next/cache";
import { cacheLife, cacheTag } from "next/cache";

export async function FullyCachedComponent() {
"use cache";
Expand All @@ -11,7 +11,7 @@ export async function FullyCachedComponent() {

export async function FullyCachedComponentWithTag() {
"use cache";
unstable_cacheTag("fullyTagged");
cacheTag("fullyTagged");
return (
<div>
<p data-testid="fully-cached-with-tag">{Date.now()}</p>
Expand All @@ -21,7 +21,7 @@ export async function FullyCachedComponentWithTag() {

export async function ISRComponent() {
"use cache";
unstable_cacheLife({
cacheLife({
stale: 1,
revalidate: 5,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/e2e/experimental/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
Expand All @@ -22,6 +22,6 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", ".next/dev/types/**/*.ts"],
"exclude": ["node_modules"]
}
4 changes: 0 additions & 4 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
// We make sure that environment variables that Next.js expects are properly defined
"process.env.NEXT_RUNTIME": '"nodejs"',
"process.env.NODE_ENV": '"production"',
// The 2 following defines are used to reduce the bundle size by removing unnecessary code
// Next uses different precompiled renderers (i.e. `app-page.runtime.prod.js`) based on if you use `TURBOPACK` or some experimental React features
// Turbopack is not supported for build at the moment, so we disable it
"process.env.TURBOPACK": "false",
// This define should be safe to use for Next 14.2+, earlier versions (13.5 and less) will cause trouble
"process.env.__NEXT_EXPERIMENTAL_REACT": `${needsExperimentalReact(nextConfig)}`,
// Fix `res.validate` in Next 15.4 (together with the `route-module` patch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { Plugin } from "esbuild";

import { getOpenNextConfig } from "../../../api/config.js";
import { patchResRevalidate } from "../patches/plugins/res-revalidate.js";
import { inlineChunksPatch } from "../patches/plugins/turbopack.js";
import { patchUseCacheIO } from "../patches/plugins/use-cache.js";
import { normalizePath } from "../utils/index.js";
import { copyWorkerdPackages } from "../utils/workerd.js";
Expand Down Expand Up @@ -210,6 +211,7 @@ async function generateBundle(
// Cloudflare specific patches
patchResRevalidate,
patchUseCacheIO,
inlineChunksPatch,
...additionalCodePatches,
]);

Expand Down
61 changes: 61 additions & 0 deletions packages/cloudflare/src/cli/build/patches/plugins/turbopack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
import type { CodePatcher } from "@opennextjs/aws/build/patch/codePatcher.js";
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";

const inlineChunksRule = `
rule:
kind: call_expression
pattern: require(resolved)
fix:
requireChunk(chunkPath)
`;

export const inlineChunksPatch: CodePatcher = {
name: "inline-turbopack-chunks",
patches: [
{
versions: ">=15.0.0",
pathFilter: getCrossPlatformPathRegex(String.raw`\[turbopack\]_runtime\.js$`, {
escape: false,
}),
contentFilter: /loadRuntimeChunkPath/,
patchCode: async ({ code, tracedFiles }) => {
const patched = patchCode(code, inlineChunksRule);

return `${patched}\n${inlineChunksFn(tracedFiles)}`;
},
},
],
};

function getInlinableChunks(tracedFiles: string[]) {
const chunks = new Set<string>();
for (const file of tracedFiles) {
if (file.includes(".next/server/chunks/") && !file.includes("[turbopack]_runtime.js")) {
chunks.add(file);
}
}
return chunks;
}

function inlineChunksFn(tracedFiles: string[]) {
// From the outputs, we extract every chunks
const chunks = getInlinableChunks(tracedFiles);
return `
function requireChunk(chunkPath) {
switch(chunkPath) {
${Array.from(chunks)
.map(
(chunk) =>
` case "${
// we only want the path after /path/to/.next/
chunk.replace(/.*\.next\//, "")
}": return require("${chunk}");`
)
.join("\n")}
default:
throw new Error(\`Not found \${chunkPath}\`);
}
}
`;
}
Loading
Loading