Unverified Commit 5cabe5e2 authored by Juny's avatar Juny Committed by GitHub

fix: set empty document files for amp first (#16934)

Fixes: https://github.com/vercel/next.js/issues/16926

I do not know this is the right way.
Please review it.
parent 64c1f726
......@@ -45,10 +45,13 @@ type DocumentFiles = {
function getDocumentFiles(
buildManifest: BuildManifest,
pathname: string
pathname: string,
inAmpMode: boolean
): DocumentFiles {
const sharedFiles: readonly string[] = getPageFiles(buildManifest, '/_app')
const pageFiles: readonly string[] = getPageFiles(buildManifest, pathname)
const pageFiles: readonly string[] = inAmpMode
? []
: getPageFiles(buildManifest, pathname)
return {
sharedFiles,
......@@ -453,8 +456,10 @@ export class Head extends Component<
const files: DocumentFiles = getDocumentFiles(
this.context.buildManifest,
this.context.__NEXT_DATA__.page
this.context.__NEXT_DATA__.page,
inAmpMode
)
return (
<head {...this.props}>
{this.context.isDevelopment && (
......@@ -769,8 +774,10 @@ export class NextScript extends Component<OriginProps> {
const files: DocumentFiles = getDocumentFiles(
this.context.buildManifest,
this.context.__NEXT_DATA__.page
this.context.__NEXT_DATA__.page,
inAmpMode
)
return (
<>
{!disableRuntimeJS && buildManifest.devFiles
......
......@@ -29,8 +29,15 @@ const context = {}
describe('AMP Usage', () => {
describe('production mode', () => {
let output = ''
beforeAll(async () => {
await nextBuild(appDir)
const result = await nextBuild(appDir, undefined, {
stdout: true,
stderr: true,
})
output = result.stdout + result.stderr
app = nextServer({
dir: join(__dirname, '../'),
dev: false,
......@@ -42,6 +49,11 @@ describe('AMP Usage', () => {
})
afterAll(() => stopApp(server))
it('should not contain missing files warning', async () => {
expect(output).toContain('Compiled successfully')
expect(output).not.toContain('Could not find files for')
})
describe('With basic usage', () => {
it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/')
......@@ -259,10 +271,18 @@ describe('AMP Usage', () => {
describe('AMP dev mode', () => {
let dynamicAppPort
let ampDynamic
let output = ''
beforeAll(async () => {
dynamicAppPort = await findPort()
ampDynamic = await launchApp(join(__dirname, '../'), dynamicAppPort)
ampDynamic = await launchApp(join(__dirname, '../'), dynamicAppPort, {
onStdout(msg) {
output += msg
},
onStderr(msg) {
output += msg
},
})
})
afterAll(() => killApp(ampDynamic))
......@@ -490,5 +510,11 @@ describe('AMP Usage', () => {
await browser.close()
}
})
it('should not contain missing files warning', async () => {
expect(output).toContain('compiled successfully')
expect(output).toContain('build page: /only-amp')
expect(output).not.toContain('Could not find files for')
})
})
})
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