Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: usage of wasm in an appDir page file using the edge runtime (#41689
) Fixes #41673 Updates the wasm `AssetBinding` filePath to be the fully qualified path during build so the files can get loaded. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
- Loading branch information
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
63 changes: 63 additions & 0 deletions
63
test/production/app-dir-edge-runtime-with-wasm/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import path from 'path' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { renderViaHTTP } from 'next-test-utils' | ||
|
||
const files = { | ||
'app/layout.jsx': ` | ||
export default function AppLayout({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>WASM Import</title> | ||
</head> | ||
<body> | ||
{children} | ||
</body> | ||
</html> | ||
) | ||
} | ||
`, | ||
'app/page.jsx': ` | ||
import wasm from '../wasm/add.wasm?module' | ||
const instance$ = WebAssembly.instantiate(wasm); | ||
async function addOne(a) { | ||
const { exports } = await instance$; | ||
return exports.add_one(a); | ||
} | ||
export default async function Page() { | ||
const two = await addOne(1) | ||
return \`1 + 1 is: $\{two}\` | ||
} | ||
export const runtime = "experimental-edge" | ||
`, | ||
'wasm/add.wasm': new FileRef(path.join(__dirname, 'add.wasm')), | ||
} | ||
|
||
describe('app-dir edge runtime with wasm', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files, | ||
dependencies: { | ||
react: 'experimental', | ||
'react-dom': 'experimental', | ||
}, | ||
nextConfig: { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should have built', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
expect(html).toContain('1 + 1 is: 2') | ||
}) | ||
}) |