Skip to content

Commit 01babce

Browse files
tahmid-23claude
andauthored
fix: drop streaming wasm calls in Turbopack runtime (#1244)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1c815de commit 01babce

29 files changed

Lines changed: 13462 additions & 43 deletions

.changeset/fuzzy-areas-clap.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: drop streaming wasm calls in Turbopack runtime
6+
7+
Turbopack replaces wasm imports using `WebAssembly.compileStreaming` and
8+
`WebAssembly.instantiateStreaming`. These functions are not available in
9+
the workerd runtime.
10+
11+
We add a helper `loadWasmChunkFn`. This is a generated switch statement
12+
that contains an import for each wasm chunk. We use static strings for
13+
all imports to ensure that all necessary wasm chunks will be detected
14+
and bundled for the final build.
15+
16+
The Turbopack patcher replaces the invocations in `loadWebAssembly` and
17+
`loadWebAssemblyModule`, using the synchronous `WebAssembly.instantiate`
18+
and redirecting to `loadWasmChunkFn`.

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ pnpm-lock.yaml
44
.vscode/setting.json
55
test-fixtures
66
test-snapshots
7-
playwright-report
7+
playwright-report
8+
examples/prisma-7/src/generated

examples/common/apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const apps = [
99
"vercel-blog-starter",
1010
"ssg-app",
1111
"prisma",
12+
"prisma-7",
1213
"next-partial-prerendering",
1314
// e2e
1415
"app-pages-router",

examples/prisma-7/.gitignore

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# open-next
21+
/.open-next/
22+
/.wrangler/
23+
24+
# production
25+
/build
26+
27+
# misc
28+
.DS_Store
29+
*.pem
30+
31+
# debug
32+
npm-debug.log*
33+
yarn-debug.log*
34+
yarn-error.log*
35+
.pnpm-debug.log*
36+
37+
# env files (can opt-in for committing if needed)
38+
.env*
39+
40+
# vercel
41+
.vercel
42+
43+
# typescript
44+
*.tsbuildinfo
45+
next-env.d.ts
46+
47+
# playwright
48+
/test-results/
49+
/playwright-report/
50+
/blob-report/
51+
/playwright/.cache/
52+
53+
# prisma
54+
/src/generated/prisma/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { configurePlaywright } from "../../common/config-e2e";
2+
3+
export default configurePlaywright("prisma-7");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { configurePlaywright } from "../../common/config-e2e";
2+
3+
export default configurePlaywright("prisma-7", {
4+
isWorker: false,
5+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { configurePlaywright } from "../../common/config-e2e";
2+
3+
export default configurePlaywright("prisma-7", { useTurbopack: true });
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.describe("playground/cloudflare", () => {
4+
test("Prisma doesn't crash", async ({ page }) => {
5+
await page.goto("/");
6+
const aliceName = await page.getByTestId("name-Alice").innerText();
7+
expect(aliceName).toBe("Alice");
8+
const aliceEmail = await page.getByTestId("email-Alice").innerText();
9+
expect(aliceEmail).toBe("alice@example.com");
10+
11+
const bobName = await page.getByTestId("name-Bob").innerText();
12+
expect(bobName).toBe("Bob");
13+
const bobEmail = await page.getByTestId("email-Bob").innerText();
14+
expect(bobEmail).toBe("bob@example.com");
15+
16+
const carolName = await page.getByTestId("name-Carol").innerText();
17+
expect(carolName).toBe("Carol");
18+
const carolEmail = await page.getByTestId("email-Carol").innerText();
19+
expect(carolEmail).toBe("carol@example.com");
20+
});
21+
});

examples/prisma-7/next.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { NextConfig } from "next";
2+
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
3+
4+
const nextConfig: NextConfig = {
5+
typescript: {
6+
ignoreBuildErrors: true,
7+
},
8+
};
9+
10+
initOpenNextCloudflareForDev();
11+
12+
export default nextConfig;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
2+
3+
export default defineCloudflareConfig({});

0 commit comments

Comments
 (0)