From 9e6c2079967bc4ebe9adef4780b686fa0009175f Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 18 Jan 2024 14:46:34 +0100 Subject: [PATCH 1/3] Remove the warning for build worker when custom webpack present --- errors/webpack-build-worker-opt-out.mdx | 15 --------------- packages/next/src/build/index.ts | 8 -------- 2 files changed, 23 deletions(-) delete mode 100644 errors/webpack-build-worker-opt-out.mdx diff --git a/errors/webpack-build-worker-opt-out.mdx b/errors/webpack-build-worker-opt-out.mdx deleted file mode 100644 index 66c628e82a40e..0000000000000 --- a/errors/webpack-build-worker-opt-out.mdx +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: Webpack Build Worker automatic opt-out ---- - -## Webpack Build Worker Opt-out - -#### Why This Error Occurred - -The Next.js config contains custom webpack configuration, as a result, the webpack build worker optimization was disabled. - -The webpack build worker optimization helps alleviate memory stress during builds and reduce out-of-memory errors although some custom configurations may not be compatible. - -#### Possible Ways to Fix It - -You can force enable the option by setting `config.experimental.webpackBuildWorker: true` in the config. diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 056edc50cad77..638c56fa328f1 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -1365,14 +1365,6 @@ export default async function build( ) nextBuildSpan.setAttribute('use-build-worker', String(useBuildWorker)) - if ( - config.webpack && - config.experimental.webpackBuildWorker === undefined - ) { - Log.warn( - 'Custom webpack configuration is detected. When using a custom webpack configuration, the Webpack build worker is disabled by default. To force enable it, set the "experimental.webpackBuildWorker" option to "true". Read more: https://nextjs.org/docs/messages/webpack-build-worker-opt-out' - ) - } if ( !useBuildWorker && (runServerAndEdgeInParallel || collectServerBuildTracesInParallel) From c5239087ffc9dba9402759cf5e687297b01b943c Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 18 Jan 2024 15:15:04 +0100 Subject: [PATCH 2/3] Fix: respect init.cache if fetch input is request instance --- packages/next/src/server/lib/patch-fetch.ts | 3 ++- test/e2e/app-dir/logging/app/fetch-no-store/page.js | 12 ++++++++++++ test/e2e/app-dir/logging/fetch-logging.test.ts | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/e2e/app-dir/logging/app/fetch-no-store/page.js diff --git a/packages/next/src/server/lib/patch-fetch.ts b/packages/next/src/server/lib/patch-fetch.ts index 3ee5873f75e8b..4835f81956315 100644 --- a/packages/next/src/server/lib/patch-fetch.ts +++ b/packages/next/src/server/lib/patch-fetch.ts @@ -236,7 +236,8 @@ export function patchFetch({ typeof (input as Request).method === 'string' const getRequestMeta = (field: string) => { - let value = isRequestInput ? (input as any)[field] : null + // If request input is present but init is not, retrieve from input first. + const value = isRequestInput && !init ? (input as any)[field] : null return value || (init as any)?.[field] } diff --git a/test/e2e/app-dir/logging/app/fetch-no-store/page.js b/test/e2e/app-dir/logging/app/fetch-no-store/page.js new file mode 100644 index 0000000000000..df09454b4c975 --- /dev/null +++ b/test/e2e/app-dir/logging/app/fetch-no-store/page.js @@ -0,0 +1,12 @@ +export default async function Page() { + await fetch( + new Request( + 'https://next-data-api-endpoint.vercel.app/api/random?request-input' + ), + { + cache: 'no-store', + } + ) + + return
Hello World!
+} diff --git a/test/e2e/app-dir/logging/fetch-logging.test.ts b/test/e2e/app-dir/logging/fetch-logging.test.ts index d5c0ef341359d..da012ef5d3cb3 100644 --- a/test/e2e/app-dir/logging/fetch-logging.test.ts +++ b/test/e2e/app-dir/logging/fetch-logging.test.ts @@ -141,6 +141,16 @@ createNextDescribe( expect(output).toContain('Cache missed reason: (noStore call)') }) }) + + it('should respect request.init.cache when use with fetch input is instance', async () => { + const logLength = next.cliOutput.length + await next.fetch('/fetch-no-store') + + await retry(() => { + const output = stripAnsi(next.cliOutput.slice(logLength)) + expect(output).toContain('Cache missed reason: (cache: no-store)') + }) + }) } } else { // No fetches logging enabled From eb54e85a0a6f0a0c2b4547e9967901d7ffd6060f Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 18 Jan 2024 15:15:42 +0100 Subject: [PATCH 3/3] Revert "Fix: respect init.cache if fetch input is request instance" This reverts commit c5239087ffc9dba9402759cf5e687297b01b943c. --- packages/next/src/server/lib/patch-fetch.ts | 3 +-- test/e2e/app-dir/logging/app/fetch-no-store/page.js | 12 ------------ test/e2e/app-dir/logging/fetch-logging.test.ts | 10 ---------- 3 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 test/e2e/app-dir/logging/app/fetch-no-store/page.js diff --git a/packages/next/src/server/lib/patch-fetch.ts b/packages/next/src/server/lib/patch-fetch.ts index 4835f81956315..3ee5873f75e8b 100644 --- a/packages/next/src/server/lib/patch-fetch.ts +++ b/packages/next/src/server/lib/patch-fetch.ts @@ -236,8 +236,7 @@ export function patchFetch({ typeof (input as Request).method === 'string' const getRequestMeta = (field: string) => { - // If request input is present but init is not, retrieve from input first. - const value = isRequestInput && !init ? (input as any)[field] : null + let value = isRequestInput ? (input as any)[field] : null return value || (init as any)?.[field] } diff --git a/test/e2e/app-dir/logging/app/fetch-no-store/page.js b/test/e2e/app-dir/logging/app/fetch-no-store/page.js deleted file mode 100644 index df09454b4c975..0000000000000 --- a/test/e2e/app-dir/logging/app/fetch-no-store/page.js +++ /dev/null @@ -1,12 +0,0 @@ -export default async function Page() { - await fetch( - new Request( - 'https://next-data-api-endpoint.vercel.app/api/random?request-input' - ), - { - cache: 'no-store', - } - ) - - return
Hello World!
-} diff --git a/test/e2e/app-dir/logging/fetch-logging.test.ts b/test/e2e/app-dir/logging/fetch-logging.test.ts index da012ef5d3cb3..d5c0ef341359d 100644 --- a/test/e2e/app-dir/logging/fetch-logging.test.ts +++ b/test/e2e/app-dir/logging/fetch-logging.test.ts @@ -141,16 +141,6 @@ createNextDescribe( expect(output).toContain('Cache missed reason: (noStore call)') }) }) - - it('should respect request.init.cache when use with fetch input is instance', async () => { - const logLength = next.cliOutput.length - await next.fetch('/fetch-no-store') - - await retry(() => { - const output = stripAnsi(next.cliOutput.slice(logLength)) - expect(output).toContain('Cache missed reason: (cache: no-store)') - }) - }) } } else { // No fetches logging enabled