Skip to content

Commit

Permalink
Add scroll-to-top workaround
Browse files Browse the repository at this point in the history
Workaround for vercel/next.js#42492
  • Loading branch information
stevenpetryk committed Jan 2, 2023
1 parent f1bbae8 commit 819214a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/app/guides/layout.tsx
@@ -1,4 +1,5 @@
"use client"
import * as React from "react"
import GuidesSidebar from "./sidebar"
import { getDocContext } from "./guides"
import { useSelectedLayoutSegments } from "next/navigation"
Expand All @@ -8,6 +9,11 @@ import fancyFx from "../../helpers/fancyFx"
export default function GuidesLayout({ children }: { children: React.ReactNode }) {
const [sectionTitleKebab, guideTitleKebab] = useSelectedLayoutSegments()

// A little hack to scroll to the top until https://github.com/vercel/next.js/issues/42492 is fixed
React.useEffect(() => {
window.scrollTo(0, 0)
}, [sectionTitleKebab, guideTitleKebab])

const { current, next, previous } = getDocContext(sectionTitleKebab, guideTitleKebab)

return (
Expand Down

0 comments on commit 819214a

Please sign in to comment.