Commit 5f70c234 authored by Jan Potoms's avatar Jan Potoms Committed by Tim Neutkens

Fix for index.js pages inside a folder named 'index' (#6423)

* Add failing test

Test case for
https://github.com/zeit/next.js/issues/6285
and
https://github.com/zeit/next.js/issues/6380

* WIP

* refactor and fix test

* not problem

* refactor back

* rename variables

like https://github.com/zeit/next.js/blob/canary/packages/next/server/on-demand-entry-handler.js#L163

* Update usage and add comment
parent 074432d9
...@@ -207,7 +207,6 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, { ...@@ -207,7 +207,6 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
async ensurePage (page) { async ensurePage (page) {
await this.waitUntilReloaded() await this.waitUntilReloaded()
page = normalizePage(page)
let normalizedPagePath let normalizedPagePath
try { try {
normalizedPagePath = normalizePagePath(page) normalizedPagePath = normalizePagePath(page)
...@@ -234,7 +233,9 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, { ...@@ -234,7 +233,9 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
const absolutePagePath = pagePath.startsWith('next/dist/pages') ? require.resolve(pagePath) : join(pagesDir, pagePath) const absolutePagePath = pagePath.startsWith('next/dist/pages') ? require.resolve(pagePath) : join(pagesDir, pagePath)
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const entryInfo = entries[page] // Makes sure the page that is being kept in on-demand-entries matches the webpack output
const normalizedPage = normalizePage(page)
const entryInfo = entries[normalizedPage]
if (entryInfo) { if (entryInfo) {
if (entryInfo.status === BUILT) { if (entryInfo.status === BUILT) {
...@@ -243,15 +244,15 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, { ...@@ -243,15 +244,15 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
} }
if (entryInfo.status === BUILDING) { if (entryInfo.status === BUILDING) {
doneCallbacks.once(page, handleCallback) doneCallbacks.once(normalizedPage, handleCallback)
return return
} }
} }
console.log(`> Building page: ${page}`) console.log(`> Building page: ${normalizedPage}`)
entries[page] = { name, absolutePagePath, status: ADDED } entries[normalizedPage] = { name, absolutePagePath, status: ADDED }
doneCallbacks.once(page, handleCallback) doneCallbacks.once(normalizedPage, handleCallback)
invalidator.invalidate() invalidator.invalidate()
......
export default () => (
<div className='nested-index'>
<p>This is an index.js nested in an index/ folder.</p>
</div>
)
...@@ -749,5 +749,11 @@ export default (context) => { ...@@ -749,5 +749,11 @@ export default (context) => {
} }
} }
}) })
it('should work on nested /index/index.js', async () => {
const browser = await webdriver(context.appPort, '/nested-index/index')
expect(await browser.elementByCss('p').text()).toBe('This is an index.js nested in an index/ folder.')
browser.close()
})
}) })
} }
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