Skip to content

Commit

Permalink
fix: set empty document files for amp first (#16934)
Browse files Browse the repository at this point in the history
Fixes: #16926

I do not know this is the right way.
Please review it.
  • Loading branch information
ka2jun8 committed Dec 22, 2020
1 parent 64c1f72 commit 5cabe5e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
15 changes: 11 additions & 4 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 && (
Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions test/integration/amphtml/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, '/')
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
})
})
})

0 comments on commit 5cabe5e

Please sign in to comment.