Skip to content

Commit

Permalink
Fix client entry unexpectedly created in app dir (#37561)
Browse files Browse the repository at this point in the history
fix client entry unexpectedly created
  • Loading branch information
shuding committed Jun 9, 2022
1 parent 0bfdf0e commit c613608
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
}

const isServerComponent = serverComponentRegex.test(absolutePagePath)
const isInsideAppDir = appDir && absolutePagePath.startsWith(appDir)

const staticInfo = await getPageStaticInfo({
nextConfig: config,
Expand All @@ -339,7 +340,7 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
page,
pageRuntime: staticInfo.runtime,
onClient: () => {
if (isServerComponent) {
if (isServerComponent || isInsideAppDir) {
// We skip the initial entries for server component pages and let the
// server compiler inject them instead.
} else {
Expand Down
4 changes: 3 additions & 1 deletion packages/next/server/dev/hot-reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ export default class HotReloader {

const isServerComponent =
serverComponentRegex.test(absolutePagePath)
const isInsideAppDir =
this.appDir && absolutePagePath.startsWith(this.appDir)

const staticInfo = await getPageStaticInfo({
pageFilePath: absolutePagePath,
Expand Down Expand Up @@ -593,7 +595,7 @@ export default class HotReloader {
},
onClient: () => {
if (!isClientCompilation) return
if (isServerComponent) {
if (isServerComponent || isInsideAppDir) {
entries[pageKey].status = BUILDING
entrypoints[bundlePath] = finalizeEntrypoint({
name: bundlePath,
Expand Down
4 changes: 3 additions & 1 deletion packages/next/server/dev/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export function onDemandEntryHandler({
const isServerComponent = serverComponentRegex.test(
pagePathData.absolutePagePath
)
const isInsideAppDir =
appDir && pagePathData.absolutePagePath.startsWith(appDir)

const pageKey = `${type}${pagePathData.page}`

Expand All @@ -217,7 +219,7 @@ export function onDemandEntryHandler({
return
}
} else {
if (type === 'client' && isServerComponent) {
if (type === 'client' && (isServerComponent || isInsideAppDir)) {
// Skip adding the client entry here.
} else {
entryAdded = true
Expand Down

0 comments on commit c613608

Please sign in to comment.