Commit Graph

3 Commits

Author SHA1 Message Date
Zack Tanner 5080edb7dc [docs] fix missing-data-scroll-behavior doc (#84651)
Fixes the code snippets for this doc.
2025-10-08 13:37:53 -07:00
Zack Tanner 36bff1060e [breaking]: enable router scroll optimization by default (#84102)
This removes the env gate that opted into old behavior. Without
explicitly setting `scroll-behavior: 'smooth'` on the document, Next.js
will not attempt to programmatically disable smooth scrolling when
performing certain router events. This is a performance optimization in
all cases that do not care about smooth scroll.
2025-09-22 16:34:29 -07:00
Zack Tanner 0cf373a585 add flag to opt into smooth scroll detection & add warning (#81563)
**What:**
`layout-router` currently forces style recalculation on every navigation by manipulating the `scroll-behavior` CSS property on the `<html>` element. This would impact most navigations, even though most don't use smooth scrolling

**Why:**
To prevent smooth scrolling during router navigation (which can feel janky), Next.js temporarily resets `scroll-behavior` to `auto`, then restores the original value (#40642). While this solves the UX issue, it causes performance overhead for the vast majority of users who don't have smooth scrolling configured.

**How:**
This PR introduces an optimization that checks for a `data-scroll-behavior="smooth"` attribute before manipulating styles. Only users who explicitly opt into smooth scrolling will experience the style recalculation.

- The existing behavior is preserved by default
- Opt-in to the new behavior by setting `experimental.optimizeRouterScrolling: true` in Next.js config
- When smooth-scroll is detected on the document, a development warning is logged to notify that the default behavior will be changing in an upcoming major.
2025-07-12 10:38:37 -07:00