Skip to content

Commit 97d7a61

Browse files
committed
Cleanup scroll and focus restoration in layout router
1 parent 9cd05ea commit 97d7a61

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

packages/next/src/client/components/layout-router.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ interface ScrollAndFocusHandlerProps {
184184
}
185185
class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerProps> {
186186
handlePotentialScroll = () => {
187-
// Handle scroll and focus, it's only applied once in the first useEffect that triggers that changed.
187+
// Handle scroll and focus, it's only applied once.
188188
const { focusAndScrollRef, segmentPath } = this.props
189189

190190
if (focusAndScrollRef.apply) {
@@ -249,7 +249,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
249249
() => {
250250
// In case of hash scroll, we only need to scroll the element into view
251251
if (hashFragment) {
252-
;(domNode as HTMLElement).scrollIntoView()
252+
domNode.scrollIntoView()
253253

254254
return
255255
}
@@ -259,7 +259,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
259259
const viewportHeight = htmlElement.clientHeight
260260

261261
// If the element's top edge is already in the viewport, exit early.
262-
if (topOfElementInViewport(domNode as HTMLElement, viewportHeight)) {
262+
if (topOfElementInViewport(domNode, viewportHeight)) {
263263
return
264264
}
265265

@@ -270,9 +270,9 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
270270
htmlElement.scrollTop = 0
271271

272272
// Scroll to domNode if domNode is not in viewport when scrolled to top of document
273-
if (!topOfElementInViewport(domNode as HTMLElement, viewportHeight)) {
273+
if (!topOfElementInViewport(domNode, viewportHeight)) {
274274
// Scroll into view doesn't scroll horizontally by default when not needed
275-
;(domNode as HTMLElement).scrollIntoView()
275+
domNode.scrollIntoView()
276276
}
277277
},
278278
{
@@ -295,10 +295,7 @@ class InnerScrollAndFocusHandler extends React.Component<ScrollAndFocusHandlerPr
295295
}
296296

297297
componentDidUpdate() {
298-
// Because this property is overwritten in handlePotentialScroll it's fine to always run it when true as it'll be set to false for subsequent renders.
299-
if (this.props.focusAndScrollRef.apply) {
300-
this.handlePotentialScroll()
301-
}
298+
this.handlePotentialScroll()
302299
}
303300

304301
render() {

0 commit comments

Comments
 (0)