Unverified Commit a1504f4c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure page.server.js matches correctly (#38236)

* Ensure app/page.server.js matches correctly

* update check
parent 8a76a8f0
...@@ -1012,7 +1012,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1012,7 +1012,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const appPathRoutes: Record<string, string> = {} const appPathRoutes: Record<string, string> = {}
Object.keys(this.appPathsManifest || {}).forEach((entry) => { Object.keys(this.appPathsManifest || {}).forEach((entry) => {
appPathRoutes[normalizeAppPath(entry)] = entry appPathRoutes[normalizeAppPath(entry) || '/'] = entry
}) })
return appPathRoutes return appPathRoutes
} }
......
...@@ -337,9 +337,8 @@ export default class DevServer extends Server { ...@@ -337,9 +337,8 @@ export default class DevServer extends Server {
}) })
if (isAppPath) { if (isAppPath) {
// TODO: should only routes ending in /index.js be route-able?
const originalPageName = pageName const originalPageName = pageName
pageName = normalizeAppPath(pageName) pageName = normalizeAppPath(pageName) || '/'
appPaths[pageName] = originalPageName appPaths[pageName] = originalPageName
if (routedPages.includes(pageName)) { if (routedPages.includes(pageName)) {
......
...@@ -29,6 +29,7 @@ export default function getRouteFromEntrypoint( ...@@ -29,6 +29,7 @@ export default function getRouteFromEntrypoint(
if (app) { if (app) {
pagePath = matchBundle(APP_ROUTE_NAME_REGEX, entryFile) pagePath = matchBundle(APP_ROUTE_NAME_REGEX, entryFile)
if (typeof pagePath === 'string' && !pagePath) pagePath = '/'
if (pagePath) return pagePath if (pagePath) return pagePath
} }
......
export default function Page(props) {
return <p>app/page.server.js</p>
}
...@@ -31,6 +31,11 @@ describe('views dir rendering', () => { ...@@ -31,6 +31,11 @@ describe('views dir rendering', () => {
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('should serve app/page.server.js at /', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('app/page.server.js')
})
describe('getServerSideProps only', () => { describe('getServerSideProps only', () => {
it('should run getServerSideProps in layout and page', async () => { it('should run getServerSideProps in layout and page', async () => {
const html = await renderViaHTTP( const html = await renderViaHTTP(
......
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