Skip to content
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

revertPop not work correctly #563

Closed
minzojian opened this issue Feb 2, 2018 · 3 comments
Closed

revertPop not work correctly #563

minzojian opened this issue Feb 2, 2018 · 3 comments

Comments

@minzojian
Copy link

please check the sandbox demo
suppose i jump from / to /pageA via click the link
i use a promt and force stop this navigation
render stoped(still render index page), however,the address has changed into /pageA
it suppose to back to /
check the source code debug snapshot
image

it looks allPaths only add new record when did history push action, why hash change not modify all paths?

@jeron-diovis
Copy link

Moreover, it breaks logic of successive transitions.

I can't reproduce it sandbox, but in normal browser it's reproducible stably.

Let's take the basic example https://reacttraining.com/react-router/web/example/basic and slightly modify it:

import React from 'react'
import {
  Router,
  Route, Switch,
  Link,
  Prompt,
} from 'react-router-dom'

// ---

import { createHashHistory } from "history"
const history = createHashHistory()

const blocker = (location, action) => {
  if (location.pathname.indexOf("about") !== -1) {
    console.log("blocked")
    return false
  }
}

// ---

const Home = () => (
  <div>
    <h2>Home</h2>
  </div>
)

const About = () => (
  <div>
    <h2>About</h2>
  </div>
)

const Topics = () => (
  <div>
    <h3>Topics</h3>
  </div>
)

const BasicExample = () => (
  <Router history={history}>
    <div>
      <Prompt when={true} message={blocker} />

      <ul>
        <li><Link to="/">Home</Link></li>
        <li><Link to="/about">About</Link></li>
        <li><Link to="/topics">Topics</Link></li>
      </ul>

      <hr/>

      <Route exact path="/" component={Home}/>
      <Switch>
      <Route path="/about" component={About}/>
      <Route path="/topics" component={Topics}/>
      </Switch>
    </div>
  </Router>
)
export default BasicExample

Now, try following scenario:

  1. Load the home page.
  2. Go to /topics by clicking link.
  • "Topics" page opened.
  1. Generate POP action which will be blocked – i.e., enter "/about" in address bar.
  • "About" page isn't opened, but path /about is in address bar
  1. Go to home page by clicking link
  • "Home" page is opened, path / is in address bar.
  1. Generate not blocked POP action by clicking "back" btn in browser.
  • Path is changed to /about but still Home page is displayed.

Expected behavior:
Transition from /topics to /about is not allowed and so ignored. History must look like this:

--(load)--> home --(link)--> topics --(link)--> home --(back)--> topics

Actual behavior:
Flag forceNextPop makes any next POP action after blocked POP action to be ignored. Despite it can be a lot of transitions before next POP actually happens.

Why forceNextPop is needed at all?

@golgistudio
Copy link

Thank you @minzojian for putting together a great test case. Just spent the last hour debugging through react-router-navigation-prompt to come to the same discovery.

When I use try to stop a goBack() call - it works
When I use tag - it doesn't - using reactstrap breadcrumbs

Anyone find a workaround?

@mjackson
Copy link
Member

This is a known issue that we cannot fix. Blocking will be removed in the next major version (see #690 for rationale).

@lock lock bot locked as resolved and limited conversation to collaborators May 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants