fix(middleware): Support wasm in bundled middleware#802
Conversation
🦋 Changeset detectedLatest commit: c2dfbd6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
commit: |
| path.join(outPackagePath, "middleware.mjs"), | ||
| ); | ||
|
|
||
| const middlewareManifest = loadMiddlewareManifest( |
There was a problem hiding this comment.
We should create a generic function for this and use it both here and there
opennextjs-aws/packages/open-next/src/build/edge/createEdgeBundle.ts
Lines 212 to 230 in fbe09ae
We also need to copy the assets
| ? `import ${file.name} from './wasm/${file.name}.wasm';` | ||
| ? // Decorate the name to avoid name collisions | ||
| `import __OpenNextWasm${i} from './wasm/${file.name}.wasm'; | ||
| globalThis.${file.name} = __OpenNextWasm${i}` |
There was a problem hiding this comment.
I'm probably missing something here, but if there is collision, wouldn't this also cause some issue with the global ?
Only things that use this (without being a separate function) should be the middleware
There was a problem hiding this comment.
.next/server/src/middleware.js would have something like
683: (e) => {
e.exports = wasm_ea010aa52414c7de383495546f15cb7d49b055fc;
}If the code here is
import wasm_ea010aa52414c7de383495546f15cb7d49b055fc from '...';Then ESBuild will change that to wasm_ea010aa52414c7de383495546f15cb7d49b055fc2 (appending a 2 at the end).
So we want the "collision" here.
| fs.copyFileSync( | ||
| path.join(options.buildDir, "middleware.mjs"), | ||
| path.join(outputPath, packagePath, "middleware.mjs"), | ||
| path.join(outPackagePath, "middleware.mjs"), |
There was a problem hiding this comment.
All this copy logic should also be in a function on this file so that everything middleware related is there https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/createMiddleware.ts.
Pretty sure we need to copy the wasm/asset files for the external middleware as well
|
Thanks for the review Nico! |
Related to opennextjs/opennextjs-cloudflare#471
2 fixes in this PR:
createServerBundlebut we also need to copy .wasm files