-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replaceState
on scroll after visiting external site
#53347
Comments
I was able to get a stack trace by:
I'll get you an unminified stack trace in a bit. |
It's next.js/packages/next/src/client/components/app-router.tsx Lines 362 to 383 in cdbea3e
👋🏻 @sophiebits. RIP #49058. |
Question is, who else from the old crew can we drag into this PR? 🤣 |
Experiencing the same issue. Tried replicating it with the next.js starter repo but was unable to. |
I was able to reproduce it as follows:
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export",
}
module.exports = nextConfig
import Link from 'next/link'
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24 m-96">
<Link href="/">self</Link><br />
<Link href="https://github.com">GitHub</Link>
</main>
)
}
It seems the "self" link is the culprit. I haven't tested if it also happens if you link to another internal page, but as soon as I remove the self link, everything works OK. I hope this helps! |
I'm surprised not more people are affected by this issue. All I had to do to reproduce it was to create a new project, enable static export, and add an external link. This should basically affect all apps using the app router and external links. Nevertheless, I created a workaround for the website I'm currently working on. I didn't want to find all external links in my app and replace them with a normal Click on the following (internal) link if you're interested (pun intended 😉): |
Just found out we're affected as well. Exactly as @michel-kraemer says above - I think almost everyone should be affected if they're using |
Just to put a fine point on it, this has nothing to do with |
When an mpa navigation takes place, we currently push the user to the new route and suspend the page indefinitely (x-ref: #49058). When navigating back, if the browser opts into using the [bfcache](https://web.dev/bfcache/), it will remain suspended and `pushRef.mpaNavigation` will be true. This means that anything that would cause the component to re-render will trigger the mpa navigation again (such as hovering over another `Link`, as reported in #53347) This PR checks to see if bfcache is being used by observing `PageTransitionEvent.persisted` and if so, resets the router state to clear out `pushRef`. Closes NEXT-1511 Fixes #53347
Fixes navigation bug with external sites (vercel/next.js#53347)
Fixes navigation bug with external sites (vercel/next.js#53347)
Fixes navigation bug with external sites (vercel/next.js#53347)
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
npx --no-install next info Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020 Binaries: Node: 20.3.1 npm: 9.6.7 Yarn: N/A pnpm: 8.6.5 Relevant Packages: next: 13.4.13-canary.6 eslint-config-next: 13.4.6 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router, Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://bright.codehike.org
To Reproduce
I haven't been able to create a minimal reproduction on Stackblitz yet, but I'm observing this issue on multiple public Next.js sites so I thought I'd report it anyway.
Example 1 – bright
replaceState
and your history is now busted.Video Demo:
bright.-.replacestate.mp4
Example 2 – my personal site
replaceState
and your history is now busted.Video Demo:
alan.-.replacestate.mp4
Describe the Bug
Here's what I can gather:
https://github.com/vercel/next.js/assets/1009/7f7227eb-ea92-4c84-ae4a-74422a599a6f
Expected Behavior
I would not expect scrolling to trigger a history
replaceState
or any navigation at all.Which browser are you using? (if relevant)
Chrome 115.0.5790.114 (arm64)
How are you deploying your application? (if relevant)
No response
NEXT-1511
The text was updated successfully, but these errors were encountered: