Skip to content

Commit 3aed76f

Browse files
authored
Unflag Automatic Prerendering (vercel#7666)
* Unflag Dynamic Routing * Unflag Automatic Prerendering * Ensure pages are lambdas for test * Fix file check * Fix tests * oof * Use lambda for document middleware test
1 parent 291eb83 commit 3aed76f

File tree

25 files changed

+90
-147
lines changed

25 files changed

+90
-147
lines changed

packages/next-server/server/config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ const defaultConfig: { [key: string]: any } = {
3030
(Number(process.env.CIRCLE_NODE_TOTAL) ||
3131
(os.cpus() || { length: 1 }).length) - 1
3232
),
33-
autoExport: false,
3433
ampBindInitData: false,
35-
exportTrailingSlash: true,
34+
exportTrailingSlash: false,
3635
terserLoader: false,
3736
profiling: false,
3837
flyingShuttle: false,

packages/next-server/server/next-server.ts

-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export default class Server {
8484
runtimeConfig?: { [key: string]: any }
8585
assetPrefix?: string
8686
canonicalBase: string
87-
autoExport: boolean
8887
documentMiddlewareEnabled: boolean
8988
dev?: boolean
9089
}
@@ -121,7 +120,6 @@ export default class Server {
121120
ampBindInitData: this.nextConfig.experimental.ampBindInitData,
122121
poweredByHeader: this.nextConfig.poweredByHeader,
123122
canonicalBase: this.nextConfig.amp.canonicalBase,
124-
autoExport: this.nextConfig.experimental.autoExport,
125123
documentMiddlewareEnabled: this.nextConfig.experimental
126124
.documentMiddleware,
127125
staticMarkup,

packages/next-server/server/render.tsx

+9-13
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ function render(
122122
}
123123

124124
type RenderOpts = {
125-
autoExport: boolean
126125
documentMiddlewareEnabled: boolean
127126
ampBindInitData: boolean
128127
staticMarkup: boolean
@@ -241,7 +240,6 @@ export async function renderToHTML(
241240
const {
242241
err,
243242
dev = false,
244-
autoExport = false,
245243
documentMiddlewareEnabled = false,
246244
ampBindInitData = false,
247245
staticMarkup = false,
@@ -279,19 +277,17 @@ export async function renderToHTML(
279277
)
280278
}
281279

282-
if (autoExport) {
283-
isStaticPage = typeof (Component as any).getInitialProps !== 'function'
284-
const defaultAppGetInitialProps =
285-
App.getInitialProps === (App as any).origGetInitialProps
286-
isStaticPage = isStaticPage && defaultAppGetInitialProps
280+
isStaticPage = typeof (Component as any).getInitialProps !== 'function'
281+
const defaultAppGetInitialProps =
282+
App.getInitialProps === (App as any).origGetInitialProps
283+
isStaticPage = isStaticPage && defaultAppGetInitialProps
287284

288-
if (isStaticPage) {
289-
// remove query values except ones that will be set during export
290-
query = {
291-
amp: query.amp,
292-
}
293-
renderOpts.nextExport = true
285+
if (isStaticPage) {
286+
// remove query values except ones that will be set during export
287+
query = {
288+
amp: query.amp,
294289
}
290+
renderOpts.nextExport = true
295291
}
296292
}
297293

packages/next/build/index.ts

+46-53
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,12 @@ export default async function build(dir: string, conf = null): Promise<void> {
282282
PAGES_MANIFEST
283283
)
284284

285-
const { autoExport } = config.experimental
286285
const staticPages = new Set<string>()
287286
const invalidPages = new Set<string>()
288287
const pageInfos = new Map<string, PageInfo>()
289-
let pagesManifest: any = {}
288+
const pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8'))
290289
let customAppGetInitialProps: boolean | undefined
291290

292-
if (autoExport) {
293-
pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8'))
294-
}
295-
296291
process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD
297292

298293
const staticCheckSema = new Sema(config.experimental.cpus, {
@@ -324,57 +319,55 @@ export default async function build(dir: string, conf = null): Promise<void> {
324319

325320
let isStatic = false
326321

327-
if (autoExport) {
328-
pagesManifest[page] = bundleRelative.replace(/\\/g, '/')
322+
pagesManifest[page] = bundleRelative.replace(/\\/g, '/')
329323

330-
const runtimeEnvConfig = {
331-
publicRuntimeConfig: config.publicRuntimeConfig,
332-
serverRuntimeConfig: config.serverRuntimeConfig,
333-
}
334-
const nonReservedPage = !page.match(/^\/(_app|_error|_document|api)/)
335-
336-
if (nonReservedPage && customAppGetInitialProps === undefined) {
337-
customAppGetInitialProps = hasCustomAppGetInitialProps(
338-
target === 'serverless'
339-
? serverBundle
340-
: path.join(
341-
distPath,
342-
SERVER_DIRECTORY,
343-
`/static/${buildId}/pages/_app.js`
344-
),
345-
runtimeEnvConfig
324+
const runtimeEnvConfig = {
325+
publicRuntimeConfig: config.publicRuntimeConfig,
326+
serverRuntimeConfig: config.serverRuntimeConfig,
327+
}
328+
const nonReservedPage = !page.match(/^\/(_app|_error|_document|api)/)
329+
330+
if (nonReservedPage && customAppGetInitialProps === undefined) {
331+
customAppGetInitialProps = hasCustomAppGetInitialProps(
332+
target === 'serverless'
333+
? serverBundle
334+
: path.join(
335+
distPath,
336+
SERVER_DIRECTORY,
337+
`/static/${buildId}/pages/_app.js`
338+
),
339+
runtimeEnvConfig
340+
)
341+
342+
if (customAppGetInitialProps) {
343+
console.warn(
344+
'Opting out of automatic exporting due to custom `getInitialProps` in `pages/_app`\n'
346345
)
346+
}
347+
}
347348

348-
if (customAppGetInitialProps) {
349-
console.warn(
350-
'Opting out of automatic exporting due to custom `getInitialProps` in `pages/_app`\n'
349+
if (customAppGetInitialProps === false && nonReservedPage) {
350+
try {
351+
await staticCheckSema.acquire()
352+
const result: any = await new Promise((resolve, reject) => {
353+
staticCheckWorkers.default(
354+
{ serverBundle, runtimeEnvConfig },
355+
(error: Error | null, result: any) => {
356+
if (error) return reject(error)
357+
resolve(result || {})
358+
}
351359
)
352-
}
353-
}
360+
})
361+
staticCheckSema.release()
354362

355-
if (customAppGetInitialProps === false && nonReservedPage) {
356-
try {
357-
await staticCheckSema.acquire()
358-
const result: any = await new Promise((resolve, reject) => {
359-
staticCheckWorkers.default(
360-
{ serverBundle, runtimeEnvConfig },
361-
(error: Error | null, result: any) => {
362-
if (error) return reject(error)
363-
resolve(result || {})
364-
}
365-
)
366-
})
367-
staticCheckSema.release()
368-
369-
if (result.isStatic) {
370-
staticPages.add(page)
371-
isStatic = true
372-
}
373-
} catch (err) {
374-
if (err.message !== 'INVALID_DEFAULT_EXPORT') throw err
375-
invalidPages.add(page)
376-
staticCheckSema.release()
363+
if (result.isStatic) {
364+
staticPages.add(page)
365+
isStatic = true
377366
}
367+
} catch (err) {
368+
if (err.message !== 'INVALID_DEFAULT_EXPORT') throw err
369+
invalidPages.add(page)
370+
staticCheckSema.release()
378371
}
379372
}
380373

@@ -411,7 +404,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
411404

412405
await writeBuildId(distDir, buildId, selectivePageBuilding)
413406

414-
if (autoExport && staticPages.size > 0) {
407+
if (staticPages.size > 0) {
415408
const exportApp = require('../export').default
416409
const exportOptions = {
417410
silent: true,
@@ -471,7 +464,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
471464
})
472465

473466
if (flyingShuttle) {
474-
if (autoExport) await flyingShuttle.mergePagesManifest()
467+
await flyingShuttle.mergePagesManifest()
475468
await flyingShuttle.save(allStaticPages, pageInfos)
476469
}
477470

packages/next/build/webpack-config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ export default async function getBaseWebpackConfig(
450450
: {}),
451451
'process.env.__NEXT_EXPERIMENTAL_DEBUG': JSON.stringify(debug),
452452
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
453-
!config.experimental.autoExport &&
454-
config.experimental.exportTrailingSlash
453+
config.experimental.exportTrailingSlash
455454
),
456455
...(isServer
457456
? { 'typeof window': JSON.stringify('undefined') }

test/integration/amp-export-validation/test/index.test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('AMP Validation on Export', () => {
2323
const toCheck = ['first', 'second', 'third.amp']
2424
await Promise.all(
2525
toCheck.map(async page => {
26-
const content = await readFile(join(outDir, `${page}/index.html`))
26+
const content = await readFile(join(outDir, `${page}.html`))
2727
await validateAMP(content.toString())
2828
})
2929
)
@@ -47,9 +47,7 @@ describe('AMP Validation on Export', () => {
4747
expect(stdout).toMatch(
4848
/warn.*The tag 'amp-video extension \.js script' is missing/
4949
)
50-
await expect(access(join(outDir, 'cat/index.html'))).resolves.toBe(
51-
undefined
52-
)
50+
await expect(access(join(outDir, 'cat.html'))).resolves.toBe(undefined)
5351
await expect(stderr).not.toMatch(
5452
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
5553
)
@@ -76,9 +74,7 @@ describe('AMP Validation on Export', () => {
7674
expect(stdout).toMatch(
7775
/error.*The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'\?/
7876
)
79-
await expect(access(join(outDir, 'dog/index.html'))).resolves.toBe(
80-
undefined
81-
)
77+
await expect(access(join(outDir, 'dog.html'))).resolves.toBe(undefined)
8278
await expect(stderr).not.toMatch(
8379
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
8480
)
@@ -108,7 +104,7 @@ describe('AMP Validation on Export', () => {
108104
expect(stdout).toMatch(
109105
/error.*The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'\?/
110106
)
111-
await expect(access(join(outDir, 'dog-cat/index.html'))).resolves.toBe(
107+
await expect(access(join(outDir, 'dog-cat.html'))).resolves.toBe(
112108
undefined
113109
)
114110
await expect(stderr).not.toMatch(

test/integration/amphtml/next.config.js

-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ module.exports = {
55
},
66
amp: {
77
canonicalBase: 'http://localhost:1234'
8-
},
9-
experimental: {
10-
autoExport: true
118
}
129
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
22
target: 'serverless',
33
experimental: {
4-
autoExport: true,
54
flyingShuttle: true
65
}
76
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
module.exports = {
2-
target: 'serverless',
3-
experimental: {
4-
autoExport: true
5-
}
2+
target: 'serverless'
63
}

test/integration/client-navigation/next.config.js

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ module.exports = {
22
onDemandEntries: {
33
// Make sure entries are not getting disposed.
44
maxInactiveAge: 1000 * 60 * 60
5-
},
6-
experimental: {
7-
autoExport: true
85
}
96
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default () => <p>Hi again 👋</p>
1+
const Another = () => <p>Hi again 👋</p>
2+
Another.getInitialProps = () => ({})
3+
export default Another
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default () => <p>Hi there 👋</p>
1+
const Home = () => <p>Hi there 👋</p>
2+
Home.getInitialProps = () => ({})
3+
export default Home

test/integration/dynamic-routing/next.config.js

-5
This file was deleted.

test/integration/export-default-map/next.config.js

-5
This file was deleted.

test/integration/export-default-map/test/index.test.js

+11-27
Original file line numberDiff line numberDiff line change
@@ -20,60 +20,44 @@ describe('Export with default map', () => {
2020

2121
it('should export with folder that has dot in name', async () => {
2222
expect.assertions(1)
23-
await expect(access(join(outdir, 'v1.12/index.html'))).resolves.toBe(
24-
undefined
25-
)
23+
await expect(access(join(outdir, 'v1.12.html'))).resolves.toBe(undefined)
2624
})
2725

2826
it('should export an amp only page to clean path', async () => {
2927
expect.assertions(1)
30-
await expect(access(join(outdir, 'docs/index.html'))).resolves.toBe(
31-
undefined
32-
)
28+
await expect(access(join(outdir, 'docs.html'))).resolves.toBe(undefined)
3329
})
3430

3531
it('should export hybrid amp page correctly', async () => {
3632
expect.assertions(2)
37-
await expect(access(join(outdir, 'some/index.html'))).resolves.toBe(
38-
undefined
39-
)
40-
await expect(access(join(outdir, 'some.amp/index.html'))).resolves.toBe(
41-
undefined
42-
)
33+
await expect(access(join(outdir, 'some.html'))).resolves.toBe(undefined)
34+
await expect(access(join(outdir, 'some.amp.html'))).resolves.toBe(undefined)
4335
})
4436

4537
it('should export nested hybrid amp page correctly', async () => {
4638
expect.assertions(3)
47-
await expect(access(join(outdir, 'docs/index.html'))).resolves.toBe(
48-
undefined
49-
)
50-
await expect(access(join(outdir, 'docs.amp/index.html'))).resolves.toBe(
51-
undefined
52-
)
39+
await expect(access(join(outdir, 'docs.html'))).resolves.toBe(undefined)
40+
await expect(access(join(outdir, 'docs.amp.html'))).resolves.toBe(undefined)
5341

54-
const html = await readFile(join(outdir, 'docs/index.html'))
42+
const html = await readFile(join(outdir, 'docs.html'))
5543
const $ = cheerio.load(html)
5644
expect($('link[rel=amphtml]').attr('href')).toBe('/docs.amp')
5745
})
5846

5947
it('should export nested hybrid amp page correctly with folder', async () => {
6048
expect.assertions(3)
61-
await expect(access(join(outdir, 'info/index.html'))).resolves.toBe(
62-
undefined
63-
)
64-
await expect(access(join(outdir, 'info.amp/index.html'))).resolves.toBe(
65-
undefined
66-
)
49+
await expect(access(join(outdir, 'info.html'))).resolves.toBe(undefined)
50+
await expect(access(join(outdir, 'info.amp.html'))).resolves.toBe(undefined)
6751

68-
const html = await readFile(join(outdir, 'info/index.html'))
52+
const html = await readFile(join(outdir, 'info.html'))
6953
const $ = cheerio.load(html)
7054
expect($('link[rel=amphtml]').attr('href')).toBe('/info.amp')
7155
})
7256

7357
it('should export hybrid index amp page correctly', async () => {
7458
expect.assertions(3)
7559
await expect(access(join(outdir, 'index.html'))).resolves.toBe(undefined)
76-
await expect(access(join(outdir, 'index.amp/index.html'))).resolves.toBe(
60+
await expect(access(join(outdir, 'index.amp.html'))).resolves.toBe(
7761
undefined
7862
)
7963

test/integration/export/next.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = phase => {
1010
bar: 'bar'
1111
},
1212
experimental: {
13-
// exportTrailingSlash: false,
13+
exportTrailingSlash: true
1414
},
1515
exportPathMap: function () {
1616
return {

0 commit comments

Comments
 (0)