- 06 Feb, 2025 27 commits
-
-
vercel-release-bot authored
-
JJ Kasper authored
This makes sure we properly copy the necessary files in standalone mode and node middleware is configured also adds regression test for this.
-
Zack Tanner authored
Errors thrown by the lint worker would only surface the error if `JEST_WORKER_ID` is present. This check was not reliably truthy in all cases (eg, when run with the vercel CLI, `JEST_WORKER_ID` wasn't present) which meant the build would fail with no helpful error message. Outside of that, it was a brittle check because if jest-worker ever changed or removed this env, or we replaced the underlying worker library, this would start failing. This updates the check to be a more explicit env variable that we control. Fixes NEXT-3994
-
Rob Pruzan authored
## What? This addresses [#68217](https://github.com/vercel/next.js/issues/68217) where middleware, incorrectly, does not run for _next/image requests. We can confirm this is not correct behavior through the explanation of middleware matchers in [docs](https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher) > The matcher config allows full regex so matching like negative lookaheads or character matching is supported. An example of a negative lookahead to match all except specific paths can be seen here: > ```typescript > export const config = { > matcher: [ > /* > * Match all request paths except for the ones starting with: > * - api (API routes) > * - _next/static (static files) > * - _next/image (image optimization files) <- This means middleware **should** run for _next/image > * - favicon.ico, sitemap.xml, robots.txt (metadata files) > */ > '/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)', > ], > } > ``` ### When did this regress The regression happened here https://github.com/vercel/next.js/pull/57161/files#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aL1245 > The diff since github isn't inlining the diff > ```diff > - let finished = await this.handleNextDataRequest(req, res, parsedUrl) > + finished = await this.handle(req, res, parsedUrl) > ``` > Note, `handle` groups calls to `handleNextDataRequest` **and** `handleImageRequest` https://github.com/vercel/next.js/pull/57161/files#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aR1316-R1328 ### Why was this a regression Inside of `handle`, there is a new call to `handleNextImageRequest` (this fn handles image optimization). This ends up causing image optimization to run before user middleware code runs. When the image optimization completes, the server behaves as if the entire middleware pipeline is complete, which is **before** user middleware code is ran https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1528-L1540 Said plainly, image optimization now runs in middleware. And when image optimization completes, it blocks user middleware code from running. Im going to assume this was an incorrect refactor since there did not seem to be a motivation for the behavior change in https://github.com/vercel/next.js/pull/57375 ### Solution The solution proposed is to follow the same behavior as `handleNextDataRequest`, which early returns during middleware: https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L728-L745 > Note, `handleNextDataRequest` has an extra condition that it only skips middleware requests when its not on edge. I’m going to assume this is not what we want for image optimization, since there was never an edge check for image optimization- to hedge I don’t have any knowledge on what can run on edge in this context And for confirmation that the new ```handleNextImageRequest``` (added in the regression mentioned) is truly redundant, you can confirm the image optimization happens when `invokePath` is specified in the request meta or when `'x-matched-path'` header exists (as far as my understanding goes, and based on the behavior I observed from runtime checks, these 2 cases should be exhaustive) : https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1470-L1526 https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1078-L1378 > what's relevant in both above snippets > ```typescript > finished = await this.normalizeAndAttachMetadata(req, res, parsedUrl) > if (finished) return > ``` > Note: it's probably optimal to not call normalizeAndAttachMetadata in the if middleware branch at all since both handlers in the function now no-op if they are handling middleware (which is guaranteed in that branch). Im not applying that change here to avoid scope of the fix, but can make the refactor upon request https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1633-L1646 ## TLDR The problem is that image optimization runs before user middleware code, and when it completes successfully, it skips running user middleware code- which means requests to _next/image will not have middleware run for them. The solution is to not run the image optimization in middleware that caused the skip Fixes #68217 --------- Co-authored-by:
Joseph Chamochumbi <jchamoch@volvocars.com>
-
Sam Ko authored
## Why? To track issues that are marked "not stale," we need to explicitly add a not stale label. https://github.com/actions/stale does not use this label by default.
-
Lee Robinson authored
This was wrong https://github.com/vercel/next.js/pull/75693
-
Niklas Mischkulnig authored
This was dead code after we removed `swc_css`
-
Shu Uesugi authored
- Fix the `npm` command - Make it clear where to place test files - Was reported here: https://github.com/vercel/next.js/issues/71773 - Relevant Next.js code: https://github.com/vercel/next.js/blob/ae5026a0fa8cd67f434cf63cc1db7d7ee696c047/packages/next/src/experimental/testmode/playwright/default-config.ts#L13 - Make it clear that `next.onFetch` only works for external requests. - Relevant Next.js code: https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/experimental/testmode/playwright/page-route.ts#L34-L40
-
Niklas Mischkulnig authored
No significant perf impact
-
Benjamin Woodruff authored
These TODOs are very old. Clean them up!
-
Jiwon Choi authored
Add and apply the merge multiple class names util. Closes NDX-664 --------- Co-authored-by:Jiachi Liu <inbox@huozhi.im>
-
Jiwon Choi authored
### Why? When fetch fails to get the original stack frames, the process to get the Runtime Errors fails. The fetch will likely fail on Storybook stories. | Before | After | |--------|--------| |  |  | ### How? Correctly reject when request fails so that it may be caught at `_getOriginalStackFrame()` and return the stack frame.
-
Zack Tanner authored
Lifts the style fix from #75718 into a separate PR. Fixes the feedback bar clipping the content:  Co-authored-by:
Jude Gao <jude.gao@vercel.com>
-
Niklas Mischkulnig authored
Way less turbo tasks Less CPU time, 300mb less memory. ``` testing against 0293c96cf32 uncell AstPath 77d7015554 (PR below in this stack) 13,65 GB TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 505.04s user 83.92s system 853% cpu 1:09.00 total TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 509.03s user 84.26s system 829% cpu 1:11.53 total snapshot in with_modules c2c661b1e9 13,3 GB TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 491.50s user 79.78s system 856% cpu 1:06.69 total TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 495.62s user 78.61s system 852% cpu 1:07.36 total ```
-
Niklas Mischkulnig authored
Our PRs were merged there
-
Janka Uryga authored
Potential fix for a leak reported in #74855 on older node versions (see [comment](https://github.com/vercel/next.js/issues/74855#issuecomment-2638334820)). ### Background When running middleware (or other edge functions) in `next start`, we wrap them in an edge runtime sandbox. this includes polyfills of `setTimeout` and `setInterval` which return `number` instead of `NodeJS.Timeout`. Unfortunately, on some older node versions, converting a `NodeJS.Timeout` to a number will cause that timeout to leak: https://github.com/nodejs/node/issues/53335 The leaked timeout will also hold onto the callback, thus also leaking anything that was closed over (which can be a lot of things!) ### Solution Ideally, users just upgrade to a Node version that includes the fix: - [node v20.16.0](https://github.com/nodejs/node/pull/53945) - [node v22.4.0](https://github.com/nodejs/node/pull/53583) - node v23.0.0 But we're currently still supporting node 18, so we can't necessarily rely on that. Luckily, as noted in the description of the nodejs issue, calling `clearTimeout` seems to unleak the timeout, so we can just do that after the callback runs! ### Unrelated stuff I did While i was at it, I also fixed a (very niche) discrepancy from how `setTimeout` and `setInterval` behave on the web. when running the callback, node sets `this` to the Timeout instance: ```js > void setTimeout(function () {console.log('this in setTimeout:', this) } ) undefined > this in setTimeout: Timeout { ... } ``` but on the web, `this` is always set to `globalThis`. Our wrapper now correctly does this. ### Testing <details> <summary>Collapsed because it's long</summary> Verifying this is kinda tricky, so bear with me... Here's a script that can verify whether calling `clearTimeout` fixes the leak by using a FinalizationRegistry and triggering GC to observe whether memory leaked or not. `setTimeoutWithFix` is a simplified version of `webSetTimeoutPolyfill` from the PR. ```js // setTimeout-test.js if (typeof gc !== 'function') { console.log('this test must be run with --expose-gc') process.exit(1) } function setTimeoutWithFix(callback, ms, ...args) { const wrappedCallback = function () { try { return callback.apply(this, args) } finally { clearTimeout(timeout) } } const timeout = setTimeout(wrappedCallback, ms) return timeout } const didFinalize = {} const registry = new FinalizationRegistry((id) => { didFinalize[id] = true }) { const id = 'node setTimeout'.padEnd(26, ' ') const timeout = setTimeout(() => {}, 0) registry.register(timeout, id) didFinalize[id] = false } { const id = 'node setTimeout as number'.padEnd(26, ' ') const timeout = setTimeout(() => {}, 0) timeout[Symbol.toPrimitive]() registry.register(timeout, id) didFinalize[id] = false } { const id = 'fixed setTimeout'.padEnd(26, ' ') const timeout = setTimeoutWithFix(() => {}, 0) registry.register(timeout, id) didFinalize[id] = false } { const id = 'fixed setTimeout as number'.padEnd(26, ' ') const timeout = setTimeoutWithFix(() => {}, 0) timeout[Symbol.toPrimitive]() registry.register(timeout, id) didFinalize[id] = false } // wait for the timeouts to run void setTimeout(() => { gc() // trigger garbage collection void registry // ...but make sure we keep the registry alive // wait a task so that finalization callbacks can run setTimeout(() => console.log('did the Timeout get released after GC?', didFinalize) ) }, 10) ``` To run it, Install the required node versions: ```bash for ver in v20.15.0 v20.16.0 v22.3.0 v22.4.0 v23.0.0; do ( nvm install "$ver" ); done ``` And run the test: ```bash for ver in v20.15.0 v20.16.0 v22.3.0 v22.4.0 v23.0.0; do ( echo '-------------------' nvm use "$ver" && node --expose-gc setTimeout-test.js echo ); done ``` The output on my machine is as follows. Note that the `node setTimeout as number` case comes up as false on the older versions (because it leaks and doesn't get finalized), but `fixed setTimeout as number` (which calls `clearTimeout`) gets released fine, which is exactly what we want. ```terminal ------------------- Now using node v20.15.0 (npm v10.7.0) did the Timeout get released after GC? { 'node setTimeout ': true, 'node setTimeout as number ': false, 'fixed setTimeout ': true, 'fixed setTimeout as number': true } ------------------- Now using node v20.16.0 (npm v10.8.1) did the Timeout get released after GC? { 'node setTimeout ': true, 'node setTimeout as number ': true, 'fixed setTimeout ': true, 'fixed setTimeout as number': true } ------------------- Now using node v22.3.0 (npm v10.8.1) did the Timeout get released after GC? { 'node setTimeout ': true, 'node setTimeout as number ': false, 'fixed setTimeout ': true, 'fixed setTimeout as number': true } ------------------- Now using node v22.4.0 (npm v10.8.1) did the Timeout get released after GC? { 'node setTimeout ': true, 'node setTimeout as number ': true, 'fixed setTimeout ': true, 'fixed setTimeout as number': true } ------------------- Now using node v23.0.0 (npm v10.9.0) did the Timeout get released after GC? { 'node setTimeout ': true, 'node setTimeout as number ': true, 'fixed setTimeout ': true, 'fixed setTimeout as number': true } ``` </details>
-
Niklas Mischkulnig authored
- Remove the last remaining `AstPath` cells - Also box a rare `CodeGen` enum variant (brings down enum size from 128 bytes to 48 bytes) - `code_gens.shrink_to_fit()` Might help memory slightly, but it's bordering on measurement noise: ``` testing against 0293c96cf32 canary b6f8743e 13,75 GB TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 507.86s user 77.80s system 847% cpu 1:09.11 total TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 503.13s user 77.86s system 855% cpu 1:07.90 total uncell AstPath 3ec676fea5 13,7 GB TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 505.04s user 83.92s system 853% cpu 1:09.00 total TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 509.03s user 84.26s system 829% cpu 1:11.53 total ```
-
Sebastian "Sebbie" Silbermann authored
-
vercel-release-bot authored
-
Tobias Koppers authored
### What? * avoid cloning SourceMap for ignore list * shrink vec before converting to Rope * shrink Strings too * shrink source map
-
Tobias Koppers authored
### What? * use new backend in next-build-test * apply effects in next-build-test * fix Dockerfile
-
Jiachi Liu authored
-
vercel-release-bot authored
-
Tobias Koppers authored
Reverts vercel/next.js#75707 canary builds timed out
-
Niklas Mischkulnig authored
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
-
Jiwon Choi authored
### Why? The color contrast of the terminal violated the WCAG standard. Example: | Yellow | Blue | |--------|--------| |  |  | ### Before #### Light   #### Dark  ### After #### Light   #### Dark  Closes https://linear.app/vercel/issue/NDX-657/fix-code-frame-color-contrast
-
Janka Uryga authored
-
- 05 Feb, 2025 13 commits
-
-
Will Binns-Smith authored
No behavior changes in this PR, just a small adjustment since while debugging it was surprising that `invalidate` was called even though it was a no-op with an empty array. Previously, `invalidate` would unconditionally get called after building, even if no work was queued. Test Plan: CI
-
Josh Story authored
When we made Request data APIs async we made them exotic to make the transition to the Promise API easier to adopt because lots of existing code probably accessed these values synchronously. `rootParams` is a new Request Data API however and it has no existing usage that is async so we do not need to support exotic access to these values. This change removes the exotic construction in favor of a simple resolved Promise.
-
vercel-release-bot authored
-
Hendrik Liebau authored
When `dynamicIO` is not enabled, and only the standalone `useCache` experimental flag is enabled, we can not encode `searchParams` as hanging promises. To still avoid unused search params from making a page dynamic (due to the `searchParams` being encoded into the cache key), we set them to a promise that resolves to an empty object, while also overwriting the to-be-invoked function for generating a cache entry with a function that creates an erroring `searchParams` prop before invoking the original function. This ensures that used `searchParams` inside of cached functions would still yield an error. closes NAR-85
-
Benjamin Woodruff authored
napi-rs only uses the cdylib version: https://github.com/napi-rs/napi-rs/blob/688a266f132f947b8002e892b78decd660d8a6ec/crates/napi/README.md#building This might(?) slightly improve compile times for certain invocations of `cargo`.
-
Hendrik Liebau authored
This allows us to catch regressions and monitor progress (e.g. for NAR-85). In addition, we're consolidating all pages in the test app to use a single root layout without a suspense boundary. Before we switched the app from using the `dynamicIO` flag to the `useCache` flag, some pages needed a suspense boundary to not fail the build.
-
Tobias Koppers authored
### What? fix a previous PR that disables dependency tracking when not needed.
-
JJ Kasper authored
This is a follow-up to https://github.com/vercel/next.js/pull/75624 which ensures middleware behaves correctly in the `src/` directory. This previously wasn't an issue since edge runtime output location isn't picky since it's just output in the middleware-manifest although with node runtime it is particular.
-
JJ Kasper authored
Seems this was failing in https://github.com/vercel/next.js/pull/75693
-
Niklas Mischkulnig authored
Don't even evaluate the left side of `obj.prop` if we know that we don't have anything in the replacement maps that matches `*.prop` anyway. This particular helps in huge files with complex code and also containing many member expressions ``` testing against 0293c96cf32 canary b6f8743e 13,75 GB TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 507.86s user 77.80s system 847% cpu 1:09.11 total TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 503.13s user 77.86s system 855% cpu 1:07.90 total mischnic/analyzer-faster-members ed38e94ba2 13,75 GB TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 499.54s user 79.28s system 857% cpu 1:07.51 total TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD= 498.31s user 76.99s system 855% cpu 1:07.27 total ```
-
Tawsif Haque authored
-
Benjamin Woodruff authored
chore(turbo-tasks): Remove support for local_cells (a specific mode of local tasks we ended up not using) (#75672) Local cells would allow us to avoid allocating real cells for data passed to local task functions. Unfortunately, in practice, we manually resolve most arguments passed to local task functions, which would defeat this optimization. I was holding onto this in the hopes that we might end up using it, but that seems fleeting: - We could get similar benefits by scanning for unreferenced cells at the end of function execution using `TraceRawVcs` at the cost of a bit of execution time. This would work even on `Vc`s that were resolved. - For ergonomics reasons, we want to eventually rename `ResolvedVc` to `Vc` (and `Vc` to something like `UnresolvedVc`), which will probably lead to us resolving even more stuff, breaking this potential optimization even more. - Cache eviction may do a good enough job of removing cells, the bigger enemy are the harder-to-evict tasks, which our current version of local tasks does do a good job of reducing. Meanwhile, it makes the code harder to follow, and could cause issues if this codepath somehow got activated.
-
Hendrik Liebau authored
When adding or removing a `"use cache"` directive to a function or module, Turbopack was not able to finish the compilation and hung. This is now fixed, and we're adding the test to prevent regression.
-