Unverified Commit be2156f6 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

fix pageKey and compiling output for on-demand-entries (#30116)

shows `compiling /_error...` instead of `compiling /next/dist/pages/_error...`
parent 8bce51d8
...@@ -170,21 +170,25 @@ export default function onDemandEntryHandler( ...@@ -170,21 +170,25 @@ export default function onDemandEntryHandler(
throw pageNotFoundError(normalizedPagePath) throw pageNotFoundError(normalizedPagePath)
} }
let pageUrl = pagePath.replace(/\\/g, '/') let bundlePath: string
let absolutePagePath: string
pageUrl = `${pageUrl[0] !== '/' ? '/' : ''}${pageUrl if (pagePath.startsWith('next/dist/pages/')) {
.replace(new RegExp(`\\.+(?:${pageExtensions.join('|')})$`), '') bundlePath = page
.replace(/\/index$/, '')}` absolutePagePath = require.resolve(pagePath)
} else {
pageUrl = pageUrl === '' ? '/' : pageUrl let pageUrl = pagePath.replace(/\\/g, '/')
const bundleFile = normalizePagePath(pageUrl) pageUrl = `${pageUrl[0] !== '/' ? '/' : ''}${pageUrl
const bundlePath = posix.join('pages', bundleFile) .replace(new RegExp(`\\.+(?:${pageExtensions.join('|')})$`), '')
const absolutePagePath = pagePath.startsWith('next/dist/pages') .replace(/\/index$/, '')}`
? require.resolve(pagePath)
: join(pagesDir, pagePath) pageUrl = pageUrl === '' ? '/' : pageUrl
const bundleFile = normalizePagePath(pageUrl)
bundlePath = posix.join('pages', bundleFile)
absolutePagePath = join(pagesDir, pagePath)
page = posix.normalize(pageUrl)
}
page = posix.normalize(pageUrl)
const normalizedPage = normalizePathSep(page) const normalizedPage = normalizePathSep(page)
const isMiddleware = normalizedPage.match(MIDDLEWARE_ROUTE) const isMiddleware = normalizedPage.match(MIDDLEWARE_ROUTE)
...@@ -194,7 +198,7 @@ export default function onDemandEntryHandler( ...@@ -194,7 +198,7 @@ export default function onDemandEntryHandler(
const addPageEntry = (type: 'client' | 'server') => { const addPageEntry = (type: 'client' | 'server') => {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
// Makes sure the page that is being kept in on-demand-entries matches the webpack output // Makes sure the page that is being kept in on-demand-entries matches the webpack output
const pageKey = `${type}${normalizedPage}` const pageKey = `${type}${page}`
const entryInfo = entries[pageKey] const entryInfo = entries[pageKey]
if (entryInfo) { if (entryInfo) {
......
...@@ -33,6 +33,7 @@ describe('basic HMR', () => { ...@@ -33,6 +33,7 @@ describe('basic HMR', () => {
const newContactPagePath = join('pages', 'hmr', '_contact.js') const newContactPagePath = join('pages', 'hmr', '_contact.js')
let browser let browser
try { try {
const start = next.cliOutput.length
browser = await webdriver(next.appPort, '/hmr/contact') browser = await webdriver(next.appPort, '/hmr/contact')
const text = await browser.elementByCss('p').text() const text = await browser.elementByCss('p').text()
expect(text).toBe('This is the contact page.') expect(text).toBe('This is the contact page.')
...@@ -53,6 +54,12 @@ describe('basic HMR', () => { ...@@ -53,6 +54,12 @@ describe('basic HMR', () => {
() => getBrowserBodyText(browser), () => getBrowserBodyText(browser),
/This is the contact page/ /This is the contact page/
) )
expect(next.cliOutput.slice(start)).toContain('compiling...')
expect(next.cliOutput.slice(start)).toContain(
'compiling /hmr/contact...'
)
expect(next.cliOutput).toContain('compiling /_error...')
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
...@@ -297,6 +304,7 @@ describe('basic HMR', () => { ...@@ -297,6 +304,7 @@ describe('basic HMR', () => {
const newPage = join('pages', 'hmr', 'new-page.js') const newPage = join('pages', 'hmr', 'new-page.js')
try { try {
const start = next.cliOutput.length
browser = await webdriver(next.appPort, '/hmr/new-page') browser = await webdriver(next.appPort, '/hmr/new-page')
expect(await browser.elementByCss('body').text()).toMatch( expect(await browser.elementByCss('body').text()).toMatch(
...@@ -317,6 +325,11 @@ describe('basic HMR', () => { ...@@ -317,6 +325,11 @@ describe('basic HMR', () => {
() => getBrowserBodyText(browser), () => getBrowserBodyText(browser),
/This page could not be found/ /This page could not be found/
) )
expect(next.cliOutput.slice(start)).toContain(
'compiling /hmr/new-page...'
)
expect(next.cliOutput.slice(start)).toContain('compiling /_error...')
} catch (err) { } catch (err) {
await next.deleteFile(newPage) await next.deleteFile(newPage)
throw err throw err
...@@ -332,6 +345,7 @@ describe('basic HMR', () => { ...@@ -332,6 +345,7 @@ describe('basic HMR', () => {
const aboutPage = join('pages', 'hmr', 'about2.js') const aboutPage = join('pages', 'hmr', 'about2.js')
const aboutContent = await next.readFile(aboutPage) const aboutContent = await next.readFile(aboutPage)
try { try {
const start = next.cliOutput.length
browser = await webdriver(next.appPort, '/hmr/about2') browser = await webdriver(next.appPort, '/hmr/about2')
await check(() => getBrowserBodyText(browser), /This is the about page/) await check(() => getBrowserBodyText(browser), /This is the about page/)
...@@ -345,6 +359,10 @@ describe('basic HMR', () => { ...@@ -345,6 +359,10 @@ describe('basic HMR', () => {
await next.patchFile(aboutPage, aboutContent) await next.patchFile(aboutPage, aboutContent)
await check(() => getBrowserBodyText(browser), /This is the about page/) await check(() => getBrowserBodyText(browser), /This is the about page/)
expect(next.cliOutput.slice(start)).toContain(
'compiling /hmr/about2...'
)
expect(next.cliOutput).toContain('compiling /_error...')
} catch (err) { } catch (err) {
await next.patchFile(aboutPage, aboutContent) await next.patchFile(aboutPage, aboutContent)
if (browser) { if (browser) {
......
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