Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ describe('cache-components PPR bot static generation bypass', () => {
files: __dirname,
})

it('should bypass static generation for DOM bot requests to avoid SSG_BAILOUT', async () => {
it('should bypass static generation for bot requests to avoid SSG_BAILOUT', async () => {
const res = await next.fetch('/foo', {
headers: {
'user-agent': 'Googlebot',
},
})
// With cache components + PPR enabled, DOM bots should behave like regular users
// With cache components + PPR enabled, bots should use dynamic rendering
// and use the fallback cache mechanism. This allows them to handle dynamic content
// like Math.random() without triggering SSG_BAILOUT errors.
expect(res.status).toBe(200)
Expand All @@ -29,4 +29,71 @@ describe('cache-components PPR bot static generation bypass', () => {
// With PPR, content is streamed, but the important thing is that
// the page rendered without a 500 error
})

it('should stream metadata for normal requests', async () => {
const $ = await next.render$('/foo')

expect($('head title').text()).not.toContain('Home')
expect($('body title').text()).toBe('Home')
})

for (const userAgent of ['Googlebot', 'Google-PageRenderer']) {
it(`should stream metadata for bot ${userAgent} without known head limitations`, async () => {
const $ = await next.render$('/foo', undefined, {
headers: {
'user-agent': userAgent,
},
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test asserts streaming metadata for 'Google-PageRenderer', but it is classified as an html-limited (blocking) bot, so the assertion is inverted and will fail.

Fix on Vercel


expect($('head title').text()).not.toContain('Home')
expect($('body title').text()).toBe('Home')
})
}

it('should block metadata for an html limited bot', async () => {
const $ = await next.render$('/foo', undefined, {
headers: {
'user-agent': 'Discordbot',
},
})

expect($('head title').text()).toBe('Home')
expect($('body title').text()).not.toContain('Home')
})
})

describe('cache-components PPR customized htmlLimitedBots', () => {
const { next } = nextTestSetup({
files: __dirname,
overrideFiles: {
'next.config.js': `
module.exports = {
cacheComponents: true,
htmlLimitedBots: /Minibot/i,
}
`,
},
})

it('should block metadata for a configured html limited bot', async () => {
const $ = await next.render$('/foo', undefined, {
headers: {
'user-agent': 'Minibot',
},
})

expect($('head title').text()).toBe('Home')
expect($('body title').text()).not.toContain('Home')
})

it('should stream metadata for Googlebot when it is not in the configured rule', async () => {
const $ = await next.render$('/foo', undefined, {
headers: {
'user-agent': 'Googlebot',
},
})

expect($('head title').text()).not.toContain('Home')
expect($('body title').text()).toBe('Home')
})
})
55 changes: 37 additions & 18 deletions test/e2e/app-dir/metadata-streaming/metadata-streaming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,44 @@ describe('app-dir - metadata-streaming', () => {
})
})

it('should send the blocking response for html limited bots', async () => {
const $ = await next.render$(
'/',
undefined, // no query
{
headers: {
'user-agent': 'Twitterbot',
},
}
)
expect(await $('title').text()).toBe('index page')
})

it('should send streaming response for headless browser bots', async () => {
const browser = await next.browser('/')
await retry(async () => {
expect(await browser.elementByCss('title').text()).toBe('index page')
for (const userAgent of ['Twitterbot', 'Mediapartners-Google']) {
it(`should send the blocking response for html limited bot ${userAgent}`, async () => {
const $ = await next.render$(
'/',
undefined, // no query
{
headers: {
'user-agent': userAgent,
},
}
)
expect($('head title').text()).toBe('index page')
expect($('body title').length).toBe(0)
})
})
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test asserts streaming (metadata in body) for html-limited Google crawlers that actually receive a blocking response (metadata in head), causing the new test cases to fail.

Fix on Vercel

for (const userAgent of [
'Googlebot',
'Google-PageRenderer',
'Google-InspectionTool',
'AdsBot-Google',
'Storebot-Google',
'googleweblight',
]) {
it(`should send a streaming response for bot ${userAgent} without known head limitations`, async () => {
const $ = await next.render$(
'/',
undefined, // no query
{
headers: {
'user-agent': userAgent,
},
}
)
expect($('head title').length).toBe(0)
expect($('body title').text()).toBe('index page')
})
}

it('should only insert metadata once into head or body', async () => {
const browser = await next.browser('/slow')
Expand Down
Loading