From 9c8aaf9d4beba6c7ad6ae81e1d2e428fa83b187a Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 20 Aug 2019 14:32:03 -0500 Subject: [PATCH] Fix build-manifest not removing _app files for modern (#8447) --- .../webpack/plugins/build-manifest-plugin.ts | 3 +- .../chunking-minimal/next.config.js | 6 ++++ .../chunking-minimal/pages/index.js | 1 + .../chunking-minimal/test/index.test.js | 33 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/integration/chunking-minimal/next.config.js create mode 100644 test/integration/chunking-minimal/pages/index.js create mode 100644 test/integration/chunking-minimal/test/index.test.js diff --git a/packages/next/build/webpack/plugins/build-manifest-plugin.ts b/packages/next/build/webpack/plugins/build-manifest-plugin.ts index 26738a0ddc..3fd14f6b76 100644 --- a/packages/next/build/webpack/plugins/build-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/build-manifest-plugin.ts @@ -25,8 +25,9 @@ const generateClientManifest = ( ): string => { const clientManifest: { [s: string]: string[] } = {} const appDependencies = new Set(assetMap.pages['/_app']) - delete assetMap.pages['/_app'] + Object.entries(assetMap.pages).forEach(([page, dependencies]) => { + if (page === '/_app') return // Filter out dependencies in the _app entry, because those will have already // been loaded by the client prior to a navigation event const filteredDeps = dependencies.filter( diff --git a/test/integration/chunking-minimal/next.config.js b/test/integration/chunking-minimal/next.config.js new file mode 100644 index 0000000000..099775a339 --- /dev/null +++ b/test/integration/chunking-minimal/next.config.js @@ -0,0 +1,6 @@ +module.exports = { + experimental: { + modern: true, + granularChunks: true + } +} diff --git a/test/integration/chunking-minimal/pages/index.js b/test/integration/chunking-minimal/pages/index.js new file mode 100644 index 0000000000..89d2bdd37e --- /dev/null +++ b/test/integration/chunking-minimal/pages/index.js @@ -0,0 +1 @@ +export default () =>

hi

diff --git a/test/integration/chunking-minimal/test/index.test.js b/test/integration/chunking-minimal/test/index.test.js new file mode 100644 index 0000000000..1f37bfa2c1 --- /dev/null +++ b/test/integration/chunking-minimal/test/index.test.js @@ -0,0 +1,33 @@ +/* eslint-env jest */ +/* global jasmine */ +import { join } from 'path' +import { readFile } from 'fs-extra' +import { nextBuild } from 'next-test-utils' + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1 + +const appDir = join(__dirname, '../') +let buildId + +describe('Chunking (minimal)', () => { + beforeAll(async () => { + await nextBuild(appDir) + buildId = await readFile(join(appDir, '.next/BUILD_ID'), 'utf8') + }) + + it('should have an empty client-manifest', async () => { + const manifest = await readFile( + join(appDir, '.next/static', buildId, '_buildManifest.js'), + 'utf8' + ) + expect(manifest).not.toMatch(/\.js/) + }) + + it('should have an empty modern client-manifest', async () => { + const manifest = await readFile( + join(appDir, '.next/static', buildId, '_buildManifest.module.js'), + 'utf8' + ) + expect(manifest).not.toMatch(/\.js/) + }) +})