-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Turbopack: expose client static assets correctly #84695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mischnic
wants to merge
10
commits into
mischnic/url-tests-e2e
Choose a base branch
from
mischnic/url-handing
base: mischnic/url-tests-e2e
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f96c362
Extend tests
mischnic a7a09b6
f test
mischnic 8bd09d3
wip
mischnic 7e70e10
f test
mischnic 686173c
f test
mischnic 50f7027
test edge
mischnic 35b3de0
f test
mischnic 4466440
test opengraph-image
mischnic efac4eb
cleanup
mischnic bc7897c
fixup assertion
mischnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,8 @@ | ||
import imported from '../../../public/vercel.png' | ||
const url = new URL('../../../public/vercel.png', import.meta.url).toString() | ||
|
||
export function GET(req, res) { | ||
return Response.json({ imported, url }) | ||
} | ||
|
||
export const runtime = 'edge' |
This file contains hidden or 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,6 @@ | ||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export function GET(req, res) { | ||
return Response.json({ imported, url }) | ||
} |
This file contains hidden or 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,14 @@ | ||
'use client' | ||
|
||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function Index(props) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+{url} | ||
</main> | ||
) | ||
} | ||
|
||
export const runtime = 'edge' |
This file contains hidden or 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,12 @@ | ||
'use client' | ||
|
||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function Index(props) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+{url} | ||
</main> | ||
) | ||
} |
This file contains hidden or 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,7 @@ | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains hidden or 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,17 @@ | ||
import icon from '../public/vercel.png' | ||
const url = new URL('../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function manifest() { | ||
return { | ||
short_name: 'Next.js', | ||
name: 'Next.js', | ||
icons: [ | ||
{ | ||
src: icon.src, | ||
type: 'image/png', | ||
sizes: '512x512', | ||
}, | ||
], | ||
description: url, | ||
} | ||
} |
This file contains hidden or 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,9 @@ | ||
import imported from '../public/vercel.png' | ||
const url = new URL('../public/vercel.png', import.meta.url).toString() | ||
|
||
export const contentType = 'text/json' | ||
|
||
// Image generation | ||
export default async function Image() { | ||
return Response.json({ imported, url }) | ||
} |
This file contains hidden or 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,12 @@ | ||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function Index(props) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+{url} | ||
</main> | ||
) | ||
} | ||
|
||
export const runtime = 'edge' |
This file contains hidden or 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,10 @@ | ||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function Index(props) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+{url} | ||
</main> | ||
) | ||
} |
This file contains hidden or 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,13 @@ | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
// @ts-ignore | ||
import imported from './public/vercel.png' | ||
const url = new URL('./public/vercel.png', import.meta.url).toString() | ||
|
||
export async function middleware(req: NextRequest) { | ||
if (req.nextUrl.toString().endsWith('/middleware')) { | ||
return Response.json({ imported, url }) | ||
} | ||
|
||
return NextResponse.next() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,13 @@ | ||
import imported from '../../../public/vercel.png' | ||
const url = new URL('../../../public/vercel.png', import.meta.url) | ||
|
||
export default (req, res) => { | ||
return new Response( | ||
JSON.stringify({ | ||
imported, | ||
url: url.toString(), | ||
}) | ||
) | ||
} | ||
|
||
export const runtime = 'experimental-edge' |
This file contains hidden or 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,12 @@ | ||
import fs from 'fs' | ||
|
||
import imported from '../../../public/vercel.png' | ||
const url = new URL('../../../public/vercel.png', import.meta.url) | ||
|
||
export default (req, res) => { | ||
res.send({ | ||
imported, | ||
url: url.toString(), | ||
size: fs.readFileSync(url).length, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,20 @@ | ||
import imported from '../../public/vercel.png' | ||
|
||
export function getServerSideProps() { | ||
return { | ||
props: { | ||
url: new URL('../../public/vercel.png', import.meta.url).toString(), | ||
}, | ||
} | ||
} | ||
|
||
export default function Index({ url }) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+ | ||
{new URL('../../public/vercel.png', import.meta.url).toString()}+{url} | ||
</main> | ||
) | ||
} | ||
|
||
export const runtime = 'experimental-edge' |
This file contains hidden or 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,12 @@ | ||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function Index(props) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+{url} | ||
</main> | ||
) | ||
} | ||
|
||
export const runtime = 'experimental-edge' |
This file contains hidden or 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,18 @@ | ||
import imported from '../../public/vercel.png' | ||
|
||
export async function getStaticProps() { | ||
return { | ||
props: { | ||
url: new URL('../../public/vercel.png', import.meta.url).toString(), | ||
}, | ||
} | ||
} | ||
|
||
export default function Index({ url }) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+ | ||
{new URL('../../public/vercel.png', import.meta.url).toString()}+{url} | ||
</main> | ||
) | ||
} |
This file contains hidden or 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,18 @@ | ||
import imported from '../../public/vercel.png' | ||
|
||
export function getServerSideProps() { | ||
return { | ||
props: { | ||
url: new URL('../../public/vercel.png', import.meta.url).toString(), | ||
}, | ||
} | ||
} | ||
|
||
export default function Index({ url }) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+ | ||
{new URL('../../public/vercel.png', import.meta.url).toString()}+{url} | ||
</main> | ||
) | ||
} |
This file contains hidden or 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,10 @@ | ||
import imported from '../../public/vercel.png' | ||
const url = new URL('../../public/vercel.png', import.meta.url).toString() | ||
|
||
export default function Index(props) { | ||
return ( | ||
<main> | ||
Hello {imported.src}+{url} | ||
</main> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code calls
.unwrap()
onasset_prefix
which isOption<RcStr>
, causing a panic if the value isNone
. This violates Rust best practices and the type contract.View Details
📝 Patch Details
Analysis
Unsafe unwrap() on Option in get_server_chunking_context violates type contract
What fails:
get_server_chunking_context()
incrates/next-core/src/next_server/context.rs:1115
calls.unwrap()
onasset_prefix: Option<RcStr>
parameter when passing it to.asset_prefix_override()
, which will panic if the value isNone
.How to reproduce: While the current caller
computed_asset_prefix()
always returnsSome(...)
, the function signature permitsNone
. Ifcomputed_asset_prefix()
is modified to returnNone
(which itsVc<Option<RcStr>>
return type allows), the code will panic at runtime with "calledOption::unwrap()
on aNone
value".Result: The code uses
.unwrap()
without handling theNone
case, violating the type contract. This is the only unwrap in the entire file and inconsistent with the similar functionget_server_chunking_context_with_client_assets
(line 1034), which correctly passesOption<RcStr>
directly to.asset_prefix()
.Expected: Functions receiving
Option<T>
should handle bothSome
andNone
cases. Per Rust error handling best practices, unwrap should only be used when failure is provably impossible, but here the type signature explicitly permitsNone
.Fixed by: Conditionally calling
.asset_prefix_override()
only whenasset_prefix
isSome
, usingif let Some(prefix) = asset_prefix { ... }
pattern.