-
Notifications
You must be signed in to change notification settings - Fork 27.8k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Error: Invariant: attempted to hard navigate to the same URL on iPhone #43088
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Hi, there were changes related to this in the most recent version of Next.js |
The above example is fixed in the latest version, can you confirm those errors are in fact from the release after updating to |
Yes, sentry is still screaming about this error even in v13.0.5-canary.6. |
I'm seeing this as well. Has anyone found a fix? Details:
|
We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate. Why was this issue marked with the
|
This has been an issue for six months now #38171. The other ticket has a reproducible environment. Let's please prioritize getting this fixed |
bumping this issue, getting the same issues in Sentry |
My guess is, that there is a bug in next.js since const disableBrowserBackForwardCache = `
window.addEventListener('pageshow', (event) => {
if (event.persisted) {
location.reload();
}
});
`;
<script dangerouslySetInnerHTML={{ __html: disableBrowserBackForwardCache }} /> We added this |
I checked some canary releases of next.js. The bug was introduced in changelog: v12.1.7-canary.31...v12.1.7-canary.32 |
Same, continuously getting this issue on Sentry. Error:
Device: |
Unfortunately, it didn't work for me either |
Getting the same issue, haven't been able to replicate it but getting sentry errors every day about it. I'm on Edit: |
We also have this error in sentry, and I can reproduce it on our staging and production environment. I think it's hard/impossible to replicate this within a sandbox. The problem manifests when we deploy a new version of our next app. We also reload/refresh the page props whenever the user focuses the page again (e.g. by coming back to the browser) by using We assume it happens because of assets path changed/are not available anymore, due to the pod change, it's handled here
No hard navigation is happening because we actually haven't changed the URL, this is when the error is logged in the console/sentry
We are currently using |
I can verify that it must be related to the middleware file / method. When I remove the middleware file and method all together, I do not get this error. However, if I have a middleware file with an exported middleware method, the error returns. |
@bberz-groma can you share the contents of your middleware file that introduces the issue and what version of Next.js you are on? |
@ijjk I am on 13.1.2. I stripped down my middleware file to only include an export of a method name like so to test the theory that it is in-fact related to the middleware file / method usage.
This results in the error seen below when I visit my deployed application |
We have hit the same issue (our error tracker being full of "attempted to hard navigate to the same URL" errors). It can happen during normal use:
In this scenario the exception seems like a false positive. |
I am also having this error while using |
Is there any update on this ? Facing this in chrome (macos) while accessing 404 page. |
I used a workaround this. Instead of adding a 404 page, I added a page named [...myErrorPage] and treated this as my 404 page. All the routes which aren't matched are routed to this file, which I can handle well. |
Same issue here. I used redirects in my
|
Please can you show how you achieved this? |
I don't find how to fix it. But in the meanwhile this get a fix, you can delete your custom 404 (404.js). This error happens to me when i handle inexistent pages. |
We pinned to This was error context/device on Android.
|
Was it related to the 404 page? And rolling it back worked but after a conversation today I'm not sure why. It seems that the issue is internal to next. As I recall, the middleware was being fired more than once which resulted in the hard navigation errors May be worth checking middleware as well. All we had to do was roll back. Sorry I'm not of more help |
Not a 404 page. It's to an existing page https://www.vendia.com/reconciliationless I'm quite confused on this error TBH. |
|
If you want to filter out this error from Sentry you can use Sentry.init({
beforeSend: (event) => {
if (event.exception?.values?.[0].value.includes('Invariant: attempted to hard navigate to the same URL')) {
return null;
}
return event;
},
}); |
I found that I easily implemented this bug, just by setting statusCode to a certain value. My environment is: {
"name": "name",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 3002",
"build": "next build",
"start": "next start -p 3000",
"lint": "next lint"
},
"dependencies": {
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@types/node": "18.15.11",
"@types/react": "18.0.35",
"@types/react-dom": "18.0.11",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"next": "13.3.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.0.4"
}
} Windows 10. The code is very simple: import { GetServerSideProps } from "next";
import Link from "next/link";
export const getServerSideProps: GetServerSideProps = async (context) => {
context.res.statusCode = 401;
return {
props: {},
};
};
export default function ImportSysIndex() {
return <Link href={`/import-sys`}>import system</Link>;
} This issue occurs when using a status code between 400 and 599. Setting the status code to a value between 200 and 299 should make it work normally. |
Same facing this issue. Both development and production |
Same issue on "next": "13.0.4". |
Why hasn't this problem been solved yet? |
Able to reproduce this issue every time when using onClick={()=> window.open("/anyURL", "_blank")} replacing it with an achor tag fixed the issue for me. |
Also still having it. It's a pity :/ |
Facing the same issue! PLEASE FIX. Its been open since 2022.. |
We are getting this error with the Googlebot and Android Browser, on regular pages (not 404). Currently on Nextjs 13.2. Does anyone know a recent fix for this? Thanks in advance! |
I'm getting this error in development as well. It happens when im using Link to route to the current url |
This might not help but in my case I have a "root" app which uses
I'm seeing this when setting Funnily enough this causes fallback to not work at all, because I've however noticed that My project is quite big but I'll try making a reproduction. Very crude reproduction:
If I visit |
Running into this error too. |
same error for chat example, just change frontend port than it happend !
reflex --version 0.2.4 |
Just started getting this error too |
same here, Im seeing this error not sure what went wrong? |
@getayush96 Can you please explain how your workaround fixed the issue? |
We are also getting this issue. Not very often but constantly. Thinking of ignoring this in sentry since we are able to handle it in client side. Next.js version For us it is happening 95% in iOS and 5% Mac OS X. 50% of mobile safari and 45% of mobile chrome. |
having this issue also, Brave latest v1.58.124, next latest v13.4.19 |
Started gettinng this issue after adding this into my next.config because i need the host as part of my getServerSideProps
|
This happens when I try to add a |
Hi everyone, The latest on this issue seems to be related to a @mattvb91 @jacobgoldfarb Is it possible to create a new bug report so we can look at both of your issues separately? I encourage others as well to create separate bug reports if they are still experiencing this on the latest version. At the moment, it is not feasible to maintain multiple edge cases (old or newly introduced) in a single large issue thread (creates a lot of noise), so I will be moving this conversation to |
I faced the same error, for the pages which had getServerSideProps. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Verify canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Home
Binaries:
Node: 18.12.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 13.0.3
eslint-config-next: 13.0.3
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Google Chrome v107.0.5304.107
How are you deploying your application? (if relevant)
next start, Digital Ocean
Describe the Bug
Hi, I just connected my production next.js app to the error tracker and noticed a lot of errors, which all give:
Error: Invariant: attempted to hard navigate to the same URL https://[domain-name]/[locale]
.The error occurs only on localized versions of website and only on iPhone mainly safari v14, 15, 16 but also on Edge Mobile Version:107.0.1418 and Chrome Mobile iOS Version:107.0.5304.
Source of all errors:
{snip} dLocale.addLocale(router.asPath,router.locale)))throw Error("Invariant: attempted to hard navigate to the same URL ".concat(url," ").concat( {snip}
Example log:

It seems that after navigation to the same localized url it can't find the [locale].json file. This website does not implement getServerSideProps or getStaticProps.
I've tested all link components both on production, development, emulated safari browser but I haven't noticed any errors/warnings in the console and I don't know what can cause this behavior for iPhone visitors.
I was using Next.js v12.2.4 but the error still occurs after upgrading to v13. I am also using next-translate v1.6.0 in my project and I don't know if the error can be related to this package or to next.js itself.
Thanks
next.config.js
i18n.json
Expected Behavior
Normal navigation to the same localized route on iPhone device.
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
Not relevant
To Reproduce
Not relevant
NEXT-1367
The text was updated successfully, but these errors were encountered: