Skip to content

Commit

Permalink
Ensure page.server.js matches correctly (#38236)
Browse files Browse the repository at this point in the history
* Ensure app/page.server.js matches correctly

* update check
  • Loading branch information
ijjk committed Jul 1, 2022
1 parent 8a76a8f commit a1504f4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const appPathRoutes: Record<string, string> = {}

Object.keys(this.appPathsManifest || {}).forEach((entry) => {
appPathRoutes[normalizeAppPath(entry)] = entry
appPathRoutes[normalizeAppPath(entry) || '/'] = entry
})
return appPathRoutes
}
Expand Down
3 changes: 1 addition & 2 deletions packages/next/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ export default class DevServer extends Server {
})

if (isAppPath) {
// TODO: should only routes ending in /index.js be route-able?
const originalPageName = pageName
pageName = normalizeAppPath(pageName)
pageName = normalizeAppPath(pageName) || '/'
appPaths[pageName] = originalPageName

if (routedPages.includes(pageName)) {
Expand Down
1 change: 1 addition & 0 deletions packages/next/server/get-route-from-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function getRouteFromEntrypoint(

if (app) {
pagePath = matchBundle(APP_ROUTE_NAME_REGEX, entryFile)
if (typeof pagePath === 'string' && !pagePath) pagePath = '/'
if (pagePath) return pagePath
}

Expand Down
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-rendering/app/page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>app/page.server.js</p>
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('views dir rendering', () => {
})
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', () => {
it('should run getServerSideProps in layout and page', async () => {
const html = await renderViaHTTP(
Expand Down

0 comments on commit a1504f4

Please sign in to comment.