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

Fix require cache conflict between app and pages #46736

Merged
merged 5 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions packages/next/src/server/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const pagePathCache =
export function getMaybePagePath(
page: string,
distDir: string,
locales?: string[],
appDirEnabled?: boolean
locales: string[] | undefined,
isAppPath: boolean
): string | null {
const cacheKey = `${page}:${distDir}:${locales}`
const cacheKey = `${page}:${distDir}:${locales}:${isAppPath}`
huozhi marked this conversation as resolved.
Show resolved Hide resolved

if (pagePathCache.has(cacheKey)) {
return pagePathCache.get(cacheKey) as string | null
Expand All @@ -41,7 +41,7 @@ export function getMaybePagePath(
const serverBuildPath = join(distDir, SERVER_DIRECTORY)
let appPathsManifest: undefined | PagesManifest

if (appDirEnabled) {
if (isAppPath) {
appPathsManifest = require(join(serverBuildPath, APP_PATHS_MANIFEST))
}
const pagesManifest = require(join(
Expand Down Expand Up @@ -94,10 +94,10 @@ export function getMaybePagePath(
export function getPagePath(
page: string,
distDir: string,
locales?: string[],
appDirEnabled?: boolean
locales: string[] | undefined,
isAppPath: boolean
): string {
const pagePath = getMaybePagePath(page, distDir, locales, appDirEnabled)
const pagePath = getMaybePagePath(page, distDir, locales, isAppPath)

if (!pagePath) {
throw new PageNotFoundError(page)
Expand All @@ -109,9 +109,9 @@ export function getPagePath(
export function requirePage(
page: string,
distDir: string,
appDirEnabled?: boolean
isAppPath: boolean
): any {
const pagePath = getPagePath(page, distDir, undefined, appDirEnabled)
const pagePath = getPagePath(page, distDir, undefined, isAppPath)
if (pagePath.endsWith('.html')) {
return promises.readFile(pagePath, 'utf8').catch((err) => {
throw new MissingStaticPage(page, err.message)
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/app-dir/similar-pages-paths/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Root({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
1 change: 1 addition & 0 deletions test/e2e/app-dir/similar-pages-paths/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => '(app/page.js)'
5 changes: 5 additions & 0 deletions test/e2e/app-dir/similar-pages-paths/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}
1 change: 1 addition & 0 deletions test/e2e/app-dir/similar-pages-paths/pages/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => '(pages/page.js)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'app-dir similar pages paths',
{
files: __dirname,
// TODO: enable development test
skipDeployment: true,
},
({ next }) => {
it('should redirect route when requesting it directly', async () => {
const res1 = await next.fetch('/')
expect(res1.status).toBe(200)
expect(await res1.text()).toContain('(app/page.js)')

const res2 = await next.fetch('/page')
expect(res2.status).toBe(200)
expect(await res2.text()).toContain('(pages/page.js)')
})
}
)