Skip to content

Commit 1970f9f

Browse files
authored
Turbopack: Always use blob: URLs for assets in middleware (#71471)
Closes PACK-3304 This was originally done in #63209 But I don't think this is correct. Without this change, the added test fails with ``` Error: failed to pipe response at pipeToNodeResponse (/next.js/packages/next/dist/server/pipe-readable.js:126:15) at async handleRequest (/next.js/packages/next/dist/server/lib/router-server.js:275:24) at async requestHandlerImpl (/next.js/packages/next/dist/server/lib/router-server.js:384:13) at async Server.requestListener (/next.js/packages/next/dist/server/lib/start-server.js:142:13) { [cause]: TypeError [ERR_INVALID_URL]: Invalid URL at new NodeError (node:internal/errors:405:5) at new URL (node:internal/url:676:13) at /next.js/test/tmp/next-test-1729241452365-597/.next/server/edge/chunks/ssr/[project]_packages_next_dist_compiled_fd94e8._.js:31684:26 { input: '/_next/static/media/noto-sans-v27-latin-regular.7e1666d1.ttf', code: 'ERR_INVALID_URL' } } ``` (because the `blob:` prefix is missing for the font static URL)
1 parent 3a9a50c commit 1970f9f

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

crates/next-api/src/middleware.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl MiddlewareEndpoint {
106106
.context("Entry module must be evaluatable")?;
107107
evaluatable_assets.push(evaluatable);
108108

109-
let edge_chunking_context = self.project.edge_chunking_context(true);
109+
let edge_chunking_context = self.project.edge_chunking_context(false);
110110

111111
let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
112112
module.ident(),

test/e2e/edge-can-use-wasm-files/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('middleware can use wasm files', () => {
111111
expect.arrayContaining([
112112
expect.objectContaining({
113113
filePath: expect.stringMatching(
114-
/^server\/edge\/chunks\/ssr\/.*\.wasm$/
114+
/^server\/edge\/chunks\/.*\.wasm$/
115115
),
116116
name: expect.stringMatching(/^wasm_/),
117117
}),

test/e2e/og-api/app/middleware.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NextResponse } from 'next/server'
2+
import { ImageResponse } from 'next/og'
3+
4+
export async function middleware(req) {
5+
if (req.nextUrl.pathname === '/middleware') {
6+
return new ImageResponse(<div>hi</div>, {
7+
width: 1200,
8+
height: 630,
9+
})
10+
}
11+
return NextResponse.next()
12+
}

test/e2e/og-api/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ describe('og-api', () => {
4343
expect(body.size).toBeGreaterThan(0)
4444
})
4545

46+
it('should work in middleware', async () => {
47+
const res = await fetchViaHTTP(next.url, '/middleware')
48+
expect(res.status).toBe(200)
49+
expect(res.headers.get('content-type')).toContain('image/png')
50+
const body = await res.blob()
51+
expect(body.size).toBeGreaterThan(0)
52+
})
53+
4654
if ((global as any).isNextStart) {
4755
it('should copy files correctly', async () => {
4856
expect(next.cliOutput).not.toContain('Failed to copy traced files')

0 commit comments

Comments
 (0)