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
d1f96581
Unverified
Commit
d1f96581
authored
Jun 09, 2025
by
Jiachi Liu
Committed by
GitHub
Jun 09, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] only serve block streaming metadata for html bots (#80272)
parent
a8ed882c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
30 deletions
+33
-30
streaming-metadata.ts
packages/next/src/server/lib/streaming-metadata.ts
+5
-4
page.js
...gration/next-image-new/app-dir/app/valid-html-w3c/page.js
+8
-7
index.test.ts
test/integration/next-image-new/app-dir/test/index.test.ts
+20
-19
No files found.
packages/next/src/server/lib/streaming-metadata.ts
View file @
d1f96581
...
@@ -12,10 +12,11 @@ export function shouldServeStreamingMetadata(
...
@@ -12,10 +12,11 @@ export function shouldServeStreamingMetadata(
htmlLimitedBots
||
HTML_LIMITED_BOT_UA_RE_STRING
,
htmlLimitedBots
||
HTML_LIMITED_BOT_UA_RE_STRING
,
'i'
'i'
)
)
return
(
// Only block metadata for HTML-limited bots
// When it's static generation, userAgents are not available - do not serve streaming metadata
if
(
userAgent
&&
blockingMetadataUARegex
.
test
(
userAgent
))
{
!!
userAgent
&&
!
blockingMetadataUARegex
.
test
(
userAgent
)
return
false
)
}
return
true
}
}
// When the request UA is a html-limited bot, we should do a dynamic render.
// When the request UA is a html-limited bot, we should do a dynamic render.
...
...
test/integration/next-image-new/app-dir/app/valid-html-w3c/page.js
View file @
d1f96581
import
Head
from
'next/head'
import
Image
from
'next/image'
import
Image
from
'next/image'
const
Page
=
()
=>
{
const
Page
=
()
=>
{
return
(
return
(
<
div
>
<
div
>
<
Head
>
<
title
>
Title
<
/title
>
<
meta
name
=
"description"
content
=
"Description..."
/>
<
link
rel
=
"icon"
type
=
"image/jpeg"
href
=
"/test.jpg"
/>
<
/Head
>
<
main
>
<
main
>
<
Image
src
=
"/test.jpg"
width
=
"400"
height
=
"400"
alt
=
"basic image"
/>
<
Image
src
=
"/test.jpg"
width
=
"400"
height
=
"400"
alt
=
"basic image"
/>
<
/main
>
<
/main
>
...
@@ -18,3 +11,11 @@ const Page = () => {
...
@@ -18,3 +11,11 @@ const Page = () => {
}
}
export
default
Page
export
default
Page
export
const
metadata
=
{
title
:
'Title'
,
description
:
'Description...'
,
icons
:
{
icon
:
'/test.jpg'
,
},
}
test/integration/next-image-new/app-dir/test/index.test.ts
View file @
d1f96581
...
@@ -1568,25 +1568,26 @@ function runTests(mode: 'dev' | 'server') {
...
@@ -1568,25 +1568,26 @@ function runTests(mode: 'dev' | 'server') {
})
})
it
(
'should be valid HTML'
,
async
()
=>
{
it
(
'should be valid HTML'
,
async
()
=>
{
let
browser
// `html-validator` underlying API (W3C validator or Nu HTML Checker) ignores or overrides custom headers.
try
{
// So we need to use a custom User-Agent to avoid streaming metadata.
browser
=
await
webdriver
(
appPort
,
'/valid-html-w3c'
)
// Otherwise the HTML will failed with validation which requires title to be rendered under the `head` tag.
await
waitFor
(
1000
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/valid-html-w3c'
,
null
,
{
expect
(
await
browser
.
hasElementByCssSelector
(
'img'
)).
toBeTruthy
()
headers
:
{
const
url
=
await
browser
.
url
()
'User-Agent'
:
'Discordbot'
,
const
result
=
(
await
validateHTML
({
},
url
,
})
format
:
'json'
,
isLocal
:
true
,
const
result
=
(
await
validateHTML
({
validator
:
'whatwg'
,
data
:
html
,
}))
as
any
format
:
'json'
,
expect
(
result
.
isValid
).
toBe
(
true
)
isLocal
:
true
,
expect
(
result
.
errors
).
toEqual
([])
validator
:
'whatwg'
,
}
finally
{
}))
as
any
if
(
browser
)
{
expect
(
result
.
isValid
).
toBe
(
true
)
await
browser
.
close
()
expect
(
result
.
errors
).
toEqual
([])
}
}
const
$
=
cheerio
.
load
(
html
)
expect
(
$
(
'img'
).
length
).
toBeGreaterThan
(
0
)
})
})
it
(
'should call callback ref cleanups when unmounting'
,
async
()
=>
{
it
(
'should call callback ref cleanups when unmounting'
,
async
()
=>
{
...
...
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