Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
df50b62e
Commit
df50b62e
authored
Apr 03, 2026
by
Jimmy Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: prevent sticky/fixed parallel route slots from consuming scroll-to-top (#79571)
parent
3a4833af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
layout-router.tsx
packages/next/src/client/components/layout-router.tsx
+49
-0
No files found.
packages/next/src/client/components/layout-router.tsx
View file @
df50b62e
...
...
@@ -97,6 +97,27 @@ function shouldSkipElement(element: HTMLElement) {
return
rectProperties
.
every
((
item
)
=>
rect
[
item
]
===
0
)
}
/**
* Check if an element or any of its ancestors (up to the body) has
* position: sticky or position: fixed. This is used to prevent parallel
* route slots rendered in sticky/fixed headers from consuming the shared
* scrollRef, which would prevent the main content area from scrolling to
* top on navigation.
*/
function
isInStickyOrFixedContainer
(
element
:
Element
):
boolean
{
let
current
:
Element
|
null
=
element
while
(
current
&&
current
!==
document
.
body
)
{
if
(
current
instanceof
HTMLElement
)
{
const
position
=
getComputedStyle
(
current
).
position
if
(
position
===
'sticky'
||
position
===
'fixed'
)
{
return
true
}
}
current
=
current
.
parentElement
}
return
false
}
/**
* Check if the top corner of the HTMLElement is in the viewport.
*/
...
...
@@ -191,6 +212,14 @@ class InnerScrollAndFocusHandlerOld extends React.Component<ScrollAndMaybeFocusH
domNode
=
domNode
.
nextElementSibling
}
// If this element is inside a sticky or fixed container (e.g. a parallel
// route rendered in a sticky header), skip this scroll handler without
// consuming the scrollRef. This allows the main content slot to handle
// the scroll instead.
if
(
isInStickyOrFixedContainer
(
domNode
))
{
return
}
// Mark as scrolled so no other segment scrolls for this navigation.
scrollRef
.
current
=
false
...
...
@@ -284,6 +313,26 @@ function InnerScrollHandlerNew(props: ScrollAndMaybeFocusHandlerProps) {
return
}
// If this element is inside a sticky or fixed container (e.g. a parallel
// route rendered in a sticky header), skip this scroll handler without
// consuming the scrollRef. This allows the main content slot to handle
// the scroll instead.
{
const
elementToCheck
:
Element
|
null
=
instance
instanceof
Element
?
instance
:
// FragmentInstance is a DOM-backed object with parentElement at
// runtime, but TypeScript's type is opaque.
(
instance
as
unknown
as
{
parentElement
:
Element
|
null
})
.
parentElement
if
(
elementToCheck
!==
null
&&
isInStickyOrFixedContainer
(
elementToCheck
)
)
{
return
}
}
// Mark as scrolled so no other segment scrolls for this navigation.
scrollRef
.
current
=
false
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment