History: Make hash history "same path" warning use console.warn

Created on 8 Jun 2017  路  5Comments  路  Source: ReactTraining/history

Could the 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack' warning be turned into a console.warn rather than a console.error? When using React Router, this warning will spam the console cause confusion and concern. Changing the warning to a console.warn will better serve it's purpose.

Also, console.warn on it's own does not support all browsers, so a different method might be required.

Line of interest: https://github.com/ReactTraining/history/blob/master/modules/createHashHistory.js#L217

Current:
hashpoppingslasher

Desired:
hashquietpopper

verified bug

All 5 comments

Agree this warning can be annoying. We're currently using the warning library to issue the warning, but it uses console.error under the hood in browsers.

Looking into this a bit further, it looks like they are opposed to using console.warn essentially because console.error provides better stack traces. I encourage you to click through on that one. There are some good links in that thread.

Anyway, we don't really need a stack trace, so I'd be open to switching to a console.warn for just this warning. We will need to do 2 things:

  • make sure the browser supports console.warn and
  • make sure the warning is stripped out of the production build

If we can do both of those I'd say we're good to go.

Hi, I am having such warning/error spamed everytime I click my link. Should I be concerned?

I do have the same warning, URL shows my path but there is no redirection. Any clue would be appreciated.

Hej @mjackson,

would you accept a PR for this?

I would also recommend renaming extending that warning to make it clear how it was caused. It took me a while to get that this isn鈥檛 something I caused with a wrong setup 馃槅

Maybe replace:

Hash history cannot PUSH the same path; a new entry will not be added to the history stack

with:

You are already on the desired location. Hash history cannot PUSH the same path; a new entry will not be added to the history stack.

Or even easier to grasp:

You clicked on a linking pointing to your current location. Hash history cannot PUSH the same path; a new entry will not be added to the history stack.

Hey everyone, sorry for the delay here.

Yes, I'd be happy to accept a PR here if anyone's up for it. It's not super high priority for me since this warning only appears in development.

Was this page helpful?
0 / 5 - 0 ratings