Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82edf3c

Browse files
committed
refactor: simplify context dependencies in loader
1 parent 3b3ec68 commit 82edf3c

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

packages/next/src/build/webpack/loaders/next-root-params-loader.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ const rootParamsLoader: webpack.LoaderDefinitionFunction<RootParamsLoaderOpts> =
1919
const allRootParams = await collectRootParamsFromFileSystem({
2020
appDir,
2121
pageExtensions,
22-
// Track every directory we traverse in case a layout gets added to it
23-
// (which would make it the new root layout for that subtree).
24-
// This is relevant both in dev (for file watching) and in prod (for caching).
25-
trackDirectory: (directory) => this.addContextDependency(directory),
2622
})
23+
// invalidate the result whenever a file/directory is added/removed inside the app dir or its subdirectories,
24+
// because that might mean that a root layout has been moved.
25+
this.addContextDependency(appDir)
2726

2827
// If there's no root params, there's nothing to generate.
2928
if (allRootParams.size === 0) {
@@ -78,11 +77,9 @@ function collectRootParams({
7877
async function findRootLayouts({
7978
appDir,
8079
pageExtensions,
81-
trackDirectory,
8280
}: {
8381
appDir: string
8482
pageExtensions: string[]
85-
trackDirectory: ((dirPath: string) => void) | undefined
8683
}) {
8784
const layoutFilenameRegex = new RegExp(
8885
`^layout\\.(?:${pageExtensions.join('|')})$`
@@ -106,8 +103,6 @@ async function findRootLayouts({
106103
throw err
107104
}
108105

109-
trackDirectory?.(directory)
110-
111106
const subdirectories: string[] = []
112107
for (const entry of dir) {
113108
if (entry.isDirectory()) {

0 commit comments

Comments
 (0)