-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
$ next info
Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Mon Jan 23 2023 17:53:48 GMT+0200 (Eastern European Standard Time)
Binaries:
Node: 16.14.2
npm: 7.17.0
Yarn: 1.22.19
pnpm: 7.13.6
Relevant packages:
next: 13.1.4
eslint-config-next: 13.1.4
react: 18.2.0
react-dom: 18.2.0
warn - Latest canary version not detected, detected: "13.1.4", newest: "13.1.5-canary.2".
Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
Read more - https://nextjs.org/docs/messages/opening-an-issue
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue
https://stackblitz.com/edit/vercel-next-js-x6badq?file=package.json
To Reproduce
- create a new Next 13 app
- add 2 large pages (both need to have a scroll bar)
- add a link at the end of the first page that redirects to the 2nd page
- very important (idk why), create an instance of the font on the second page:
import { Inter } from '@next/font/google';
const inter = Inter({ subsets: ['latin'] });
- run the app
- on the home page, scroll down and click on the link
- notice the scroll position on the 2nd page is not at the top
2nd related issue
Now, remove the font instance (const inter = Inter({ subsets: ['latin'] });) from the second page. Test the app again and notice the scroll bar being at the top but still has a small scroll. It's not top: 0. (Reproduction link)
Temporary workaround
In order to fix this issue, for now, I added this in my main layout.tsx file. I had to convert it to a client component:
const pathname = usePathname()
useEffect(() => {
window.scroll(0, 0)
}, [pathname])
Describe the Bug
Clicking on a link that redirects to a page makes the scroll bar be scrolled instead of having it at the top of the page. Requirements of the bug are described above
Expected Behavior
Expecting the scroll bar to be at the top without removing the font instance from the 2nd page.
To note that, on my real app, I don't have this font instance. Si the bug is probably introduced by some other package.
Which browser are you using? (if relevant)
Chrome 109
How are you deploying your application? (if relevant)
next start