Unverified Commit 85ef3638 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: don't treat metadata routes as RSC (#82911)

Metadata routes are just `route.ts`\-s in diguise.
Treat them the same regarding the layer (`app-route`) and whether to emit client reference/server actions manifests for them (= don't).

This fixes a panic:

```
thread 'tokio-runtime-worker' panicked at crates/next-api/src/dynamic_imports.rs:70:26:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

https://vercel.slack.com/archives/C05TH5T3DS8/p1755670936074369
parent d6794f43
...@@ -1134,8 +1134,8 @@ impl AppEndpoint { ...@@ -1134,8 +1134,8 @@ impl AppEndpoint {
next_config: Vc<NextConfig>, next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> { ) -> Result<Vc<AppEntry>> {
Ok(get_app_metadata_route_entry( Ok(get_app_metadata_route_entry(
self.app_project.rsc_module_context(), self.app_project.route_module_context(),
self.app_project.edge_rsc_module_context(), self.app_project.edge_route_module_context(),
self.app_project.project().project_path().owned().await?, self.app_project.project().project_path().owned().await?,
self.page.clone(), self.page.clone(),
*self.app_project.project().next_mode().await?, *self.app_project.project().next_mode().await?,
...@@ -1194,11 +1194,7 @@ impl AppEndpoint { ...@@ -1194,11 +1194,7 @@ impl AppEndpoint {
AppEndpointType::Metadata { metadata } => ( AppEndpointType::Metadata { metadata } => (
false, false,
false, false,
if matches!(metadata, MetadataItem::Dynamic { .. }) { EmitManifests::Minimal,
EmitManifests::Full
} else {
EmitManifests::Minimal
},
matches!(metadata, MetadataItem::Dynamic { .. }), matches!(metadata, MetadataItem::Dynamic { .. }),
), ),
}; };
......
import { DynamicComponent } from '../client-reference'
export async function GET() {
return new Response('Hello ' + typeof DynamicComponent)
}
'use client'
import dynamic from 'next/dynamic'
export const DynamicComponent = dynamic(() => import('./dynamic-component'))
const DynamicImportComponent = () => {
return (
<div id="dynamic-component">This is a dynamically imported component</div>
)
}
export default DynamicImportComponent
import { DynamicComponent } from './client-reference'
globalThis.foo = DynamicComponent
export default function sitemap() {
return [
{
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
]
}
...@@ -64,6 +64,16 @@ describe('app dir - next/dynamic', () => { ...@@ -64,6 +64,16 @@ describe('app dir - next/dynamic', () => {
expect($('#dynamic-component').text()).not.toContain('loading') expect($('#dynamic-component').text()).not.toContain('loading')
}) })
it('should ignore next/dynamic in routes', async () => {
const response = await next.fetch('/api')
expect(await response.text()).toEqual('Hello function')
})
it('should ignore next/dynamic in sitemap', async () => {
const response = await next.fetch('/sitemap.xml')
expect(await response.text()).toInclude('<changefreq>yearly</changefreq>')
})
if (isNextDev) { if (isNextDev) {
it('should directly raise error when dynamic component error on server', async () => { it('should directly raise error when dynamic component error on server', async () => {
const pagePath = 'app/default-loading/dynamic-component.js' const pagePath = 'app/default-loading/dynamic-component.js'
......
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