Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure page.server.js matches correctly #38236

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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