Unverified Commit 1970f9fb authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: Always use blob: URLs for assets in middleware (#71471)

Closes PACK-3304

This was originally done in https://github.com/vercel/next.js/pull/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)
parent 3a9a50c2
...@@ -106,7 +106,7 @@ impl MiddlewareEndpoint { ...@@ -106,7 +106,7 @@ impl MiddlewareEndpoint {
.context("Entry module must be evaluatable")?; .context("Entry module must be evaluatable")?;
evaluatable_assets.push(evaluatable); evaluatable_assets.push(evaluatable);
let edge_chunking_context = self.project.edge_chunking_context(true); let edge_chunking_context = self.project.edge_chunking_context(false);
let edge_files = edge_chunking_context.evaluated_chunk_group_assets( let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
module.ident(), module.ident(),
......
...@@ -111,7 +111,7 @@ describe('middleware can use wasm files', () => { ...@@ -111,7 +111,7 @@ describe('middleware can use wasm files', () => {
expect.arrayContaining([ expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
filePath: expect.stringMatching( filePath: expect.stringMatching(
/^server\/edge\/chunks\/ssr\/.*\.wasm$/ /^server\/edge\/chunks\/.*\.wasm$/
), ),
name: expect.stringMatching(/^wasm_/), name: expect.stringMatching(/^wasm_/),
}), }),
......
import { NextResponse } from 'next/server'
import { ImageResponse } from 'next/og'
export async function middleware(req) {
if (req.nextUrl.pathname === '/middleware') {
return new ImageResponse(<div>hi</div>, {
width: 1200,
height: 630,
})
}
return NextResponse.next()
}
...@@ -43,6 +43,14 @@ describe('og-api', () => { ...@@ -43,6 +43,14 @@ describe('og-api', () => {
expect(body.size).toBeGreaterThan(0) expect(body.size).toBeGreaterThan(0)
}) })
it('should work in middleware', async () => {
const res = await fetchViaHTTP(next.url, '/middleware')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png')
const body = await res.blob()
expect(body.size).toBeGreaterThan(0)
})
if ((global as any).isNextStart) { if ((global as any).isNextStart) {
it('should copy files correctly', async () => { it('should copy files correctly', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files') expect(next.cliOutput).not.toContain('Failed to copy traced files')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment