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

parallel routes: fix next-provided default.js not being resolved if the config doesn't specify .js #48446

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
28 changes: 20 additions & 8 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const PAGE_SEGMENT = 'page$'

type PathResolver = (
pathname: string,
resolveDir?: boolean
resolveDir?: boolean,
internal?: boolean
) => Promise<string | undefined>

export type ComponentsType = {
Expand Down Expand Up @@ -171,10 +172,7 @@ async function createTreeCodeFromPath(
loaderContext,
pageExtensions,
}: {
resolver: (
pathname: string,
resolveDir?: boolean
) => Promise<string | undefined>
resolver: PathResolver
resolvePath: (pathname: string) => Promise<string>
resolveParallelSegments: (
pathname: string
Expand Down Expand Up @@ -365,7 +363,11 @@ async function createTreeCodeFromPath(
(await resolver(
`${appDirPrefix}${segmentPath}/${actualSegment}/default`
)) ??
(await resolver(`next/dist/client/components/parallel-route-default`))
(await resolver(
`next/dist/client/components/parallel-route-default`,
false,
true
))

props[normalizeParallelKey(adjacentParallelSegment)] = `[
'__DEFAULT__',
Expand Down Expand Up @@ -437,6 +439,13 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {

const resolve = this.getResolve(resolveOptions)

// a resolver for internal next files. We need to override the extensions, in case
// a project doesn't have the same ones as used by next.
const internalResolve = this.getResolve({
...resolveOptions,
extensions: [...extensions, '.js', '.jsx', '.ts', '.tsx'],
})

const normalizedAppPaths =
typeof appPaths === 'string' ? [appPaths] : appPaths || []

Expand Down Expand Up @@ -471,13 +480,16 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {

return Object.entries(matched)
}
const resolver: PathResolver = async (pathname, resolveDir) => {
const resolver: PathResolver = async (pathname, resolveDir, internal) => {
if (resolveDir) {
return createAbsolutePath(appDir, pathname)
}

try {
const resolved = await resolve(this.rootContext, pathname)
const resolved = await (internal ? internalResolve : resolve)(
this.rootContext,
pathname
)
this.addDependency(resolved)
return resolved
} catch (err: any) {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/parallel-routes-not-found/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @type {import('next').NextConfig}
*/
const nextConfig = {
pageExtensions: ['tsx', 'ts'],
experimental: { appDir: true },
}

Expand Down