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

Warning: A history supports only one prompt at a time (ie, using multiple <NavigationPrompt /> is a bad idea?) #42

Open
rsmylskibc opened this issue Nov 7, 2018 · 9 comments

Comments

@rsmylskibc
Copy link

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
If you are using NavigationPrompt inside multiple components that can be rendered inside a parent component, Warning: A history supports only one prompt at a time is thrown if you change from rendering one component that uses NavigationPrompt to another component using NavigationPrompt.

If the current behavior is a bug, please provide the steps to reproduce.
Create two components that include NavigationPrompt as a child.
Create a component that will render the first component by default, then conditionally render the second component instead on a state change.

What is the expected behavior?
NavigationPrompt should appropriately bind to history.block utilizing lifecycle methods, not binding before it needs to.

With doing some of my own debugging, if history.block is not set to state.unblock during the constructor, but in componentDidMount this collision does not occur.

@ZacharyRSmith
Copy link
Owner

Thanks, @rsmylskibc ! Would you please make a pull request for this change?

kuhelbeher added a commit to kuhelbeher/react-router-navigation-prompt that referenced this issue Jan 13, 2019
ZacharyRSmith added a commit that referenced this issue Jan 18, 2019
@ghost
Copy link

ghost commented Jan 31, 2019

@ZacharyRSmith I have the latest 1.8.4 version and I still have the "Warning: A history supports only one prompt at a time" error message...

P.S. both components are present in the DOM (I have two tabs and toggle between them on state change)

@ZacharyRSmith ZacharyRSmith reopened this Jan 31, 2019
@ZacharyRSmith
Copy link
Owner

@Ameer157 thanks for bringing this to my attention, would you please PR a fix, or at least provide a reproducible example? Or @kuhelbeher, could you look more into this? Thanks!

@ghost
Copy link

ghost commented Feb 3, 2019

@Ameer157 thanks for bringing this to my attention, would you please PR a fix, or at least provide a reproducible example? Or @kuhelbeher, could you look more into this? Thanks!

Thanks for the attention @ZacharyRSmith 🥇

The bug can be reproduced by having two instances of </NavigationPrompt> into the DOM.
As I mentioned in my previous comment, that I have two tabs that toggle between two components and each component has its own react from and </NavigationPrompt> Since the two components are present in the DOM at the same time I receive the "Warning: A history supports only one prompt at a time" error.

I hope I was clear enough

@ZacharyRSmith
Copy link
Owner

Yes, you are clear, thanks.

Just as an FYI: I don't have the time to debug this. Hopefully someone else will be able to look into this!

@ghost
Copy link

ghost commented Feb 3, 2019

Yes, you are clear, thanks.

Just as an FYI: I don't have the time to debug this. Hopefully someone else will be able to look into this!

No worries, thanks anyways!
I will try to have someone with better React experience than me to look into this as well ;)

@kuhelbeher
Copy link
Contributor

kuhelbeher commented Feb 10, 2019

I had a different case - two components with <NavigationPrompt> was neighbours and when I was switching between them error occurs.

@Ameer157, maybe you can place <NavigationPropmpt> component in parent component instead of two component which present in the DOM at the same time. This should fix your problem.

@ghost
Copy link

ghost commented Feb 11, 2019

I had a different case - two components with <NavigationPrompt> was neighbours and when I was switching between them error occurs.

@Ameer157, maybe you can place <NavigationPropmpt> component in parent component instead of two component which present in the DOM at the same time. This should fix your problem.

Thanks for the tip @kuhelbeher - this is a perfect walk-around 👍

@ZacharyRSmith

@ZacharyRSmith ZacharyRSmith changed the title Warning: A history supports only one prompt at a time Warning: A history supports only one prompt at a time (ie, using multiple <NavigationPrompt /> is a bad idea?) Feb 16, 2019
@Joachimzeelmaekers
Copy link

@Ameer157, maybe you can place <NavigationPropmpt> component in parent component instead of two component which present in the DOM at the same time. This should fix your problem.

Works for me too! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants