- 06 Aug, 2025 15 commits
-
-
nextjs-bot authored
-
Zack Tanner authored
This PR fixes an infinite loop bug that occurred when using `cacheLife({ stale: 0 })` with `clientSegmentCache`. When the server returned a stale time of 0 seconds, cache entries would have `staleAt = Date.now()`, making them immediately stale. The cache would evict these entries on the same tick they were created, triggering continuous refetch requests. The fix updates the minimum stale time to be 30s, in the event that the server sends a low value. The rationale being that a value lower than 30s here would render prefetching ineffective. This prevents the immediate eviction while still respecting the server's intent for very short-lived cache entries. Closes NAR-269 -
Andrew Clark authored
Small update to #82383. Instead of using a special symbol to represent the "virtual" segments that get inserted into the loader tree for parallel routes, we can represent them like route groups, since they serve the same purpose. That will allow us to remove a special case in the param parsing logic, since we have to skip groups regardless; both will be skipped by the same check.
-
zoomdong authored
When use externalType: `global` or `script` under utoopack(turbopack only use esm or cjs external): like externalType is global , and the external package is react. The generate external module code like: ```ts 263: ((__turbopack_context__) => { "use strict"; const mod = globalThis["react"]; __turbopack_context__.n(mod); }), ``` The real function of runtime code `__turbopack_context__.n` is `exportNamespace`, its code as follows: ```ts module.exports = module.namespaceObject = namespace ``` And when we import the module as following: ```ts import react from "react"; console.log(react.version); ``` it will be bundled as: ```ts var __TURBOPACK__imported__module__263__ = __turbopack_context__.i(263); console.log(__TURBOPACK__imported__module__263__["default"]); ``` The `__turbopack_context__i` is esmImport, it will return the module when the module contains `namespaceObject` without `interopEsm`: ```ts function esmImport() { const module = getOrInstantiateModuleFromParent(id, this.m) // any ES module has to have `module.namespaceObject` defined. if (module.namespaceObject) return module.namespaceObject return interopEsm(); } ``` So the following case if we use a react umd module(which doesn't have a `default export`) as our external package, code `console.log(__TURBOPACK__imported__module__263__["default"]);` will output `undefined`(which webpack can output the right version). I just change export wrapper the externalType: global and script here(which now only consumed by utoopack), so the esmImport will execute `interopEsm` function here to make our code work fine. We test the case under utoopack and here is our pr: https://github.com/umijs/mako/pull/2097/files. --------- Co-authored-by:Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
-
Vercel Release Bot authored
This auto-generated PR updates the production integration test manifest used when testing Rspack.
-
Joseph authored
Closes: https://linear.app/vercel/issue/DOC-4862/tailwind-css-modules --------- Co-authored-by:
Rich Haines <hello@richardhaines.dev>
-
Janka Uryga authored
Closes NAR-262
-
Janka Uryga authored
`unstable_isUnrecognizedActionError` is a new API that lets user code check if a server action call failed because the action id wasn't recognized by the server. This usually happens as a result of version skew between client and server. Example usage: ```ts try { await myServerAction(); } catch (err) { if (unstable_isUnrecognizedActionError(err)) { // The client is from a different deployment than the server. // Reloading the page will fix this mismatch. window.alert("Please refresh the page and try again"); return; } } ``` It can also be used to create a special error boundary, like we do in the tests added here. Note that this API is not a complete solution to this problem, as it doesn't allow handling failures for MPA actions (sent without JS). We might add a more complete API for this in the future to address that. -
Jiwon Choi authored
Rspack `testing for test/development/tsconfig-path-reloading` is failing often these days. Noticed `test/development/jsconfig-path-reloading` is already in the manifest of the "failed" section. - [Failed CI](https://github.com/vercel/next.js/actions/runs/16671025870/job/47187245042?pr=81396#step:34:504) - [DataDog](https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40test.service%3Anextjs%20%40test.status%3Afail%20%40test.name%3A%28%22tsconfig-path-reloading%20tsconfig%20added%20after%20starting%20dev%20should%20automatically%20fast%20refresh%20content%20when%20path%20is%20added%20without%20error%22%20OR%20%22tsconfig-path-reloading%20tsconfig%20should%20automatically%20fast%20refresh%20content%20when%20path%20is%20added%20without%20error%22%29&agg_m=count&agg_m_source=base&agg_t=count¤tTab=overview&eventStack=&fromUser=false&index=citest&start=1753875198762&end=1754479998762&paused=false)
-
Andrew Clark authored
This will be used to roll out an internal implementation change; it won't ever be a user-facing configuration. The plan is to remove it as soon as the feature is properly tested.
-
Sebastian "Sebbie" Silbermann authored
-
Joseph authored
Fixes: https://github.com/vercel/next.js/issues/82379 Also fixing the Metadata snippets at the bottom of the page
-
Joseph authored
Feedback on the csp guide updates
-
nextjs-bot authored
-
- 05 Aug, 2025 16 commits
-
-
Steven authored
Fonts were not protected from version skew so this PR fixes it https://nextjs.org/docs/14/app/building-your-application/deploying#version-skew
-
nextjs-bot authored
-
Zack Tanner authored
When constructing the loader tree for parallel route segments, we inject a `children` segment, which could contain things like slot level layout/error/loading files. We want a way to distinguish between these virtual segments that exist just for organizational purposes rather than relying on `children`. This updates the loader tree construction code to give these more unique names. In the future, we should see if we can remove the need for this virtual segment if there are no special files needed at that segment of the tree.
-
Niklas Mischkulnig authored
To pull in a minifier bugfix: https://github.com/swc-project/swc/pull/10950 Fixes error locations again: https://github.com/swc-project/swc/issues/10930 https://vercel.slack.com/archives/C02HY34AKME/p1753429211338319 Blocked on https://github.com/swc-project/plugins/pull/514
-
Joshua Hannaford authored
-
Jiwon Choi authored
### Why? The issue was brought up when the app had rewrites (say `/ -> /foo`), and the page used `useRouter.push/replace` to add the search queries; it used the destination's pathname (`/foo?query=1`) instead of just adding the query (`/?query=1`). Current Behavior: https://github.com/vercel/next.js/actions/runs/16647831682/job/47112716254?pr=82236#step:34:156 ### How? Therefore, as we handle the hash (`#`), if the target path only needs a query `?`, we may use `router.asPath` by default for static routes to resolve cases with rewrites. However, if it is a dynamic route, it needs to be able to interpolate the query (for `/[id]` segment, `/?id=1` interpolates to `/1` route), so use `router.pathname`. Finally, if it is suspected to be a rewritten path, use `router.asPath`. **Note:** There is an edge case where the pathname is dynamic, and also a rewrite path to the same segment. E.g. in `/[slug]` path, rewrite `/foo -> /bar` In this case, it will be treated as a non-rewritten path and possibly interpolate the query string. E.g., `/any?slug=foo` will become the content of `/foo`, not rewritten as `/bar`. This is currently a trade-off of not resolving rewrite paths on every Router/Link call, but using a lighter route regex pattern check. Fixes https://github.com/vercel/next.js/issues/81476
-
Jiwon Choi authored
In minimal mode, if there was `/[slug].js` with `notFound: true` on the same segment of `_error.js`, `req.url` and `ctx.asPath` were returned as `/[slug]`, since it was re-initialized to the request url. Therefore, don't re-initialize the URL if it is in minimal mode && is the `_error` page. Fixes NEXT-4660 --------- Co-authored-by:JJ Kasper <jj@jjsweb.site>
-
xusd320 authored
feat(turbopack): improve compile-time define value to support more data types and expr evaluation (#81042) Co-authored-by:graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
-
Josh Story authored
When creating spans with OTel random values must be created to follow the OTel spec and is expected in practical implementations. While it is a loose concession Next.js will allow spans to be created while prerendering that have ids generated with random values. and by reading the current time from the system clock. This is pragmatic but potentially risky because if you are not careful and for instance wrap a "use cache" function in a span it is possible you will accidentally pass the span into the cache function causing it to miss on every invocation due to the random nature of one of it's arguments. To defend against this we do check whether `startActiveSpan` is being passed a Cache Function. However it is easy to circumvent by wrapping it in an intermediate function or by using startSpan and context.with yourself. In the long run we should consider tainting the Span objects created in these scopes so they cannot be sent through to a cache. I will consider a follow up PR to land this if we determine taint is likely to be stabilized in React. The pratical implementation of this change is to patch the tracer provider so that it always provides a patched tracer which exits the workUnitStorage on span start/creation and re-enters the scope on inner function exectuion.
-
Michal authored
The PR fixes issues in two different guides. ### PPR In PPR, the code for jsx and tsx versions should use the language switcher. Currently, these are displayed below each other in the guide which seems unintentional. ### ISR This change fixes multiple issues: **fixes in the example:** the example currently does not match the text below (_Here's how this example works:_). It says: > If /blog/26 is requested, Next.js will generate and cache this page on-demand that is of course not correct because there are only 25 blog posts returned from the API. No blog post data is returned for `/blog/26`, making this example wrong and confusing. By slicing the posts and supplying only 24 of 25 blog posts for static generation during the build process, the guide becomes much more explicit - the 25th blog post can be used for inspecting the workings of the on-the-fly generation and caching. Turning `dynamicParams` to `false` or `true`, one can now truly test this behaviour with the 25th blog. Second, the same example in Pages Router docs includes: > return { paths, fallback: false } In this case, again, this part below: > If /blog/26 is requested, Next.js will generate and cache this page on-demand is incorrect. When setting `fallback` to `false`, the page is never generated on-demand and returns 404 instead as there is no 26th blog post in the fetched data. So the fix changes the value of `fallback` to `blocking`, to mirror the App Router's `dynamicParams` value in the guide. This makes is more consistent and, more importantly, reproducible example. **clarifying the on-demand section:** The sections dedicated to **on-demand revalidation** do not currently mention that revalidation works differently from the time-based one. One may assume the first request after on-demand revalidation returns stale data (just like time-based). But that's not true, the next request after on-demand revalidation (with Server Actions for example) generates the content on-the-fly and returns fresh data right away. It wasn't clear to me so I tested it myself and was surprised (and happy) that it is this smart. I think it's very important to clarify this distinction in the guide. ----- I hope this makes sense. I'm quite responsive these days and will change it based on your feedback (if any). Thanks! <!-- 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 # --> --------- Co-authored-by:Joseph <joseph.chamochumbi@vercel.com>
-
Jiwon Choi authored
For cases when the root span's status returned 500, the span status returned `OK`. This results in inaccurate telemetry, as users may expect the span to indicate an error when a 500 occurs. Failed CI: https://github.com/vercel/next.js/actions/runs/16633984270/job/47070403977?pr=82212#step:34:427 Also, the OTel documentation states: > For HTTP status codes in the 5xx range, as well as any other code the client failed to interpret, span status SHOULD be set to Error. x-ref: https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status Therefore, set the root span to `Error` when the status is in the 5xx range. In addition, as the document states: > When instrumentation detects such errors it SHOULD set span status to Error and SHOULD set the error.type attribute. Added `error.type` attributes to places where sets `Error` span status. Fixes NEXT-4668
-
Niklas Mischkulnig authored
I looked through all TODOs if there are any remaining "todo fix this for prod builds"-style comments, but there weren't any. But some of them are outdated now
-
xusd320 authored
-
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 # -->
-
Niklas Mischkulnig authored
Closes PACK-5183 Based on https://github.com/swc-project/swc/issues/10944#issuecomment-3120775091, we need to run styled-jsx after typescript Fixes this crash ``` entered unreachable code: This visitor does not support TypeScript. This method fails for optimization purposes. Encountered in unreachable visitor: visit_ts_interface_decl ``` This has become more pressing as swc seems to have turned the debug_assertion into a proper panic/crash in recent versions (I was seeing SIGSEGV when building some app): https://vercel.slack.com/archives/C03EWR7LGEN/p1754390155508789?thread_ts=1753477535.369549&cid=C03EWR7LGEN We now have three phases/stages: - preprocess: to strip typescript/decorators (so to normalize the syntax) - main: for transforms that want to operate on "standard" EcmaScript (though still with raw JSX) - postprocess: react transform, preset-env, etc (so low level "codegen")
-
huperniketes authored
-
- 04 Aug, 2025 9 commits
-
-
nextjs-bot authored
-
Luke Sandberg authored
# Add automated benchmark runner for module-cost ## What? This PR adds an automated benchmark runner for the module-cost benchmark, allowing for consistent measurement of module loading and execution times. ## Why? It is to tedious and error prone to run the benchmark. ## Usage Build `next` and turbopack however you like ``` pnpm i pnpm prepare-bench pnpm build-webpack (or build-turbopack) pnpm benchmark ``` ## How? v0 mostly
-
Benjamin Woodruff authored
I noticed we had two copies of this library. There are a few minor API changes (some things that were properties are now methods, "message" is now "kind"), and I switched our error type over to use `RcStr` since it implements `Clone`.
-
Joseph authored
Fixes: https://github.com/vercel/next.js/issues/81776
-
nextjs-bot authored
-
devin-ai-integration[bot] authored
# Improve Content Security Policy Documentation This PR comprehensively improves the Next.js Content Security Policy (CSP) documentation to address community feedback from Reddit and GitHub discussions about gaps in the current documentation. ## Changes Made ### 1. Enhanced Nonce Flow Explanation - Added detailed section explaining how Next.js automatically detects and applies nonces during server-side rendering - Clarified the 3-step process: middleware generation → Next.js extraction → automatic application - Explained that developers don't need to manually add nonces to every script tag ### 2. Static vs Dynamic Rendering Documentation - Added comprehensive section explaining performance implications of using nonces - Documented that nonces force all pages into dynamic rendering - Explained trade-offs: slower page loads, increased server load, no CDN caching - Added guidance on when to use nonces vs alternatives ### 3. Experimental SRI (Subresource Integrity) Documentation - Documented the experimental `sri.algorithm` configuration option - Explained hash-based CSP as an alternative to nonces that preserves static generation - Included configuration examples and benefits/limitations - Noted that SRI is webpack-only, App Router only, and experimental ### 4. Development vs Production Considerations - Added section addressing environment-specific CSP requirements - Documented need for `'unsafe-eval'` in development for HMR - Provided conditional CSP examples based on NODE_ENV ### 5. Comprehensive Troubleshooting Section - Added solutions for error pages that don't work with strict CSP - Documented third-party script integration with CSP - Included common CSP violation fixes - Added examples for both App Router and Pages Router ### 6. Practical Examples - Static site with hash-based CSP using SRI - Dynamic site with nonce-based CSP - Mixed approach for different page types - Environment-aware CSP configuration ### 7. Enhanced Pages Router Documentation - Added `_document.tsx` nonce access example - Improved `getServerSideProps` examples - Added third-party script integration examples ## Community Feedback Addressed This PR directly addresses the Reddit thread feedback about: -
❌ "it is not clear that the nonce is then picked up by the rest of the pages" →✅ Added detailed nonce flow explanation -❌ "it is not clear that the pages therefore are not statically generated anymore" →✅ Added static vs dynamic rendering section -❌ "The solution of being able to provide the sha256 hashes... is not supported, and it is not mentioned in the documentation" →✅ Added experimental SRI documentation -❌ Poor documentation of strict CSP implementation →✅ Added comprehensive examples and troubleshooting ## Technical Details - **File Modified**: `docs/01-app/02-guides/content-security-policy.mdx` - **Lines Added**: 642 insertions - **Maintains**: Existing documentation structure and Next.js conventions - **Supports**: Both App Router and Pages Router with appropriate switcher components ## Testing - Verified all code examples use correct Next.js APIs and patterns - Ensured documentation follows existing Next.js docs structure - Confirmed all referenced configuration options exist in the codebase - Validated that experimental features are properly marked as such --- **Link to Devin run**: https://app.devin.ai/sessions/e7e5fa95dc0146b3ab79aac72c53ed13 **Requested by**: lee@vercel.com --------- Co-authored-by:Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by:
lee@vercel.com <lee@vercel.com> Co-authored-by:
Joseph Chamochumbi <joseph.chamochumbi@vercel.com>
-
Andrew Clark authored
When performing a segment prefetch, we send a "segment path" to the server, which represents the particular segment that we're requesting. Originally, I thought these needed to fully encode all the param values, but since we already request the segments within the context of a particular target page, it's unnecessary — the base URL already contains all the param information (and is indeed the source of truth for where the param values come from). The only thing we need to put in the paths are the param names. On the client, though, these segments are cached across pages (that's the whole point of the Segment Cache). So in the prefetch cache, we do need to cache them by their concrete param values. Splitting out the param names and the param values into separate keys will allow us to implement "fallback PPR" behavior for the client, where if a segment entry does not reference a particular param, it can be reused for all possible values of that param. (We already do this for search strings.) For now, I've split the current "segment path" key into two separate keys, which I'm calling the "cache key" and the "request key". It's a bit confusing since we have so many different types of cache keys, but I think it's OK for now — this will be refactored soon anyway to support the fallback PPR behavior. Despite the line count, most of this PR is just a mechanical refactor. Most of it was done by tab completion in Cursor. The substance of the change is in the `segment-value-encoding.ts` file.
-
PuppyOne authored
## What? Added a new "React Developer Tools" section to the debugging documentation. ## Why? This PR resolves #82308 which highlighted that React DevTools - a fundamental debugging tool for React applications - was missing from Next.js debugging documentation. Since the Next.js framework is built on React, React DevTools is crucial for: - Inspecting component hierarchies - Debugging state and props - Identifying performance issues - Understanding application structure ## How? Inserted a concise section between "Client-side code" and "Server-side code" in [docs/01-app/02-guides/debugging.mdx](https://github.com/vercel/next.js/blob/canary/docs/01-app/02-guides/debugging.mdx): - Introduces developers to the essential React debugging tool and its key features - Direct users to the corresponding React documentation ### Checklist: Improving Documentation - [x] Ran `pnpm prettier-fix` to ensure proper formatting - [x] Followed the Docs Contribution Guide: https://nextjs.org/docs/community/contribution-guide Closes #82308 Co-authored-by:
Joseph <joseph.chamochumbi@vercel.com>
-
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 # -->
-