Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
73f6b7dc
Unverified
Commit
73f6b7dc
authored
Oct 01, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 01, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respect reexports from metadata API routes (#70508) (#70647)
backport #70508 Co-authored-by:
JJ Kasper
<
jj@jjsweb.site
>
parent
e1da07e7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
141 additions
and
17 deletions
+141
-17
next-metadata-route-loader.ts
...t/src/build/webpack/loaders/next-metadata-route-loader.ts
+34
-17
manifest.ts
test/production/app-dir/metadata-revalidate/app/manifest.ts
+22
-0
opengraph-image.tsx
...metadata-revalidate/app/revalidate/og/opengraph-image.tsx
+24
-0
robots.ts
test/production/app-dir/metadata-revalidate/app/robots.ts
+14
-0
sitemap.ts
test/production/app-dir/metadata-revalidate/app/sitemap.ts
+12
-0
metadata-revalidate.test.ts
...n/app-dir/metadata-revalidate/metadata-revalidate.test.ts
+26
-0
turbopack-build-tests-manifest.json
test/turbopack-build-tests-manifest.json
+9
-0
No files found.
packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts
View file @
73f6b7dc
...
...
@@ -14,6 +14,27 @@ function errorOnBadHandler(resourcePath: string) {
`
}
/* re-export the userland route configs */
async
function
createReExportsCode
(
resourcePath
:
string
,
loaderContext
:
webpack
.
LoaderContext
<
any
>
)
{
const
exportNames
=
await
getLoaderModuleNamedExports
(
resourcePath
,
loaderContext
)
// Re-export configs but avoid conflicted exports
const
reExportNames
=
exportNames
.
filter
(
(
name
)
=>
name
!==
'default'
&&
name
!==
'generateSitemaps'
)
return
reExportNames
.
length
>
0
?
`export {
${
reExportNames
.
join
(
', '
)}
} from
${
JSON
.
stringify
(
resourcePath
)}
\n`
:
''
}
const
cacheHeader
=
{
none
:
'no-cache, no-store'
,
longCache
:
'public, immutable, no-transform, max-age=31536000'
,
...
...
@@ -83,7 +104,10 @@ export const dynamic = 'force-static'
return
code
}
function
getDynamicTextRouteCode
(
resourcePath
:
string
)
{
async
function
getDynamicTextRouteCode
(
resourcePath
:
string
,
loaderContext
:
webpack
.
LoaderContext
<
any
>
)
{
return
`\
/* dynamic asset route */
import { NextResponse } from 'next/server'
...
...
@@ -94,6 +118,7 @@ const contentType = ${JSON.stringify(getContentType(resourcePath))}
const fileType =
${
JSON
.
stringify
(
getFilenameAndExtension
(
resourcePath
).
name
)}
${
errorOnBadHandler
(
resourcePath
)}
${
await
createReExportsCode
(
resourcePath
,
loaderContext
)}
export async function GET() {
const data = await handler()
...
...
@@ -110,7 +135,10 @@ export async function GET() {
}
// <metadata-image>/[id]/route.js
function
getDynamicImageRouteCode
(
resourcePath
:
string
)
{
async
function
getDynamicImageRouteCode
(
resourcePath
:
string
,
loaderContext
:
webpack
.
LoaderContext
<
any
>
)
{
return
`\
/* dynamic image route */
import { NextResponse } from 'next/server'
...
...
@@ -122,6 +150,7 @@ const handler = imageModule.default
const generateImageMetadata = imageModule.generateImageMetadata
${
errorOnBadHandler
(
resourcePath
)}
${
await
createReExportsCode
(
resourcePath
,
loaderContext
)}
export async function GET(_, ctx) {
const { __metadata_id__, ...params } = ctx.params || {}
...
...
@@ -160,10 +189,6 @@ async function getDynamicSiteMapRouteCode(
resourcePath
,
loaderContext
)
// Re-export configs but avoid conflicted exports
const
reExportNames
=
exportNames
.
filter
(
(
name
)
=>
name
!==
'default'
&&
name
!==
'generateSitemaps'
)
const
hasGenerateSiteMaps
=
exportNames
.
includes
(
'generateSitemaps'
)
if
(
...
...
@@ -197,15 +222,7 @@ const contentType = ${JSON.stringify(getContentType(resourcePath))}
const fileType =
${
JSON
.
stringify
(
getFilenameAndExtension
(
resourcePath
).
name
)}
${
errorOnBadHandler
(
resourcePath
)}
${
''
/* re-export the userland route configs */
}
${
reExportNames
.
length
>
0
?
`export {
${
reExportNames
.
join
(
', '
)}
} from
${
JSON
.
stringify
(
resourcePath
)}
\n`
:
''
}
${
await
createReExportsCode
(
resourcePath
,
loaderContext
)}
export async function GET(_, ctx) {
const { __metadata_id__, ...params } = ctx.params || {}
...
...
@@ -266,11 +283,11 @@ const nextMetadataRouterLoader: webpack.LoaderDefinitionFunction<MetadataRouteLo
let
code
=
''
if
(
isDynamic
===
'1'
)
{
if
(
fileBaseName
===
'robots'
||
fileBaseName
===
'manifest'
)
{
code
=
getDynamicTextRouteCode
(
filePath
)
code
=
await
getDynamicTextRouteCode
(
filePath
,
this
)
}
else
if
(
fileBaseName
===
'sitemap'
)
{
code
=
await
getDynamicSiteMapRouteCode
(
filePath
,
page
,
this
)
}
else
{
code
=
getDynamicImageRouteCode
(
filePath
)
code
=
await
getDynamicImageRouteCode
(
filePath
,
this
)
}
}
else
{
code
=
await
getStaticAssetRouteCode
(
filePath
,
fileBaseName
)
...
...
test/production/app-dir/metadata-revalidate/app/manifest.ts
0 → 100644
View file @
73f6b7dc
import
type
{
MetadataRoute
}
from
'next'
export
default
function
manifest
():
MetadataRoute
.
Manifest
{
return
{
name
:
'Next.js App'
,
short_name
:
'Next.js App'
,
description
:
'Next.js App'
,
start_url
:
'/'
,
display
:
'standalone'
,
background_color
:
'#fff'
,
theme_color
:
'#fff'
,
icons
:
[
{
src
:
'/favicon.ico'
,
sizes
:
'any'
,
type
:
'image/x-icon'
,
},
],
}
}
export
const
revalidate
=
5
test/production/app-dir/metadata-revalidate/app/revalidate/og/opengraph-image.tsx
0 → 100644
View file @
73f6b7dc
import
{
ImageResponse
}
from
'next/og'
/* without generateImageMetadata */
export
default
function
og
()
{
return
new
ImageResponse
(
(
<
div
style=
{
{
width
:
'100%'
,
height
:
'100%'
,
display
:
'flex'
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
fontSize
:
128
,
background
:
'lavender'
,
}
}
>
Open Graph
</
div
>
)
)
}
export
const
revalidate
=
5
test/production/app-dir/metadata-revalidate/app/robots.ts
0 → 100644
View file @
73f6b7dc
import
type
{
MetadataRoute
}
from
'next'
export
default
function
robots
():
MetadataRoute
.
Robots
{
return
{
rules
:
{
userAgent
:
'*'
,
allow
:
'/'
,
disallow
:
'/private/'
,
},
sitemap
:
'https://acme.com/sitemap.xml'
,
}
}
export
const
revalidate
=
5
test/production/app-dir/metadata-revalidate/app/sitemap.ts
0 → 100644
View file @
73f6b7dc
export
default
function
sitemap
()
{
return
[
{
url
:
'https://acme.com'
,
lastModified
:
new
Date
(),
changeFrequency
:
'yearly'
,
priority
:
1
,
},
]
}
export
const
revalidate
=
5
test/production/app-dir/metadata-revalidate/metadata-revalidate.test.ts
0 → 100644
View file @
73f6b7dc
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'app-dir - metadata-revalidate'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should contain the routes in prerender manifest'
,
async
()
=>
{
const
manifestContent
=
await
next
.
readFile
(
'.next/prerender-manifest.json'
)
const
prerenderManifest
=
JSON
.
parse
(
manifestContent
)
expect
(
prerenderManifest
.
routes
[
'/revalidate/og/opengraph-image'
]
.
initialRevalidateSeconds
).
toBe
(
5
)
expect
(
prerenderManifest
.
routes
[
'/manifest.webmanifest'
].
initialRevalidateSeconds
).
toBe
(
5
)
expect
(
prerenderManifest
.
routes
[
'/robots.txt'
].
initialRevalidateSeconds
).
toBe
(
5
)
expect
(
prerenderManifest
.
routes
[
'/sitemap.xml'
].
initialRevalidateSeconds
).
toBe
(
5
)
})
})
test/turbopack-build-tests-manifest.json
View file @
73f6b7dc
...
...
@@ -15075,6 +15075,15 @@
"flakey"
:
[],
"runtimeError"
:
false
},
"test/production/app-dir/metadata-revalidate/metadata-revalidate.test.ts"
:
{
"passed"
:
[],
"failed"
:
[
"app-dir - metadata-revalidate should contain the routes in prerender manifest"
],
"pending"
:
[],
"flakey"
:
[],
"runtimeError"
:
false
},
"test/production/middleware-typescript/test/index.test.ts"
:
{
"passed"
:
[],
"failed"
:
[
"middleware-typescript should have built and started"
],
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment