-
Notifications
You must be signed in to change notification settings - Fork 46
Don’t propagate RESET event from switch router to nested stack routers #43
Conversation
There is no sense to spread root stack router RESET event to all nested stack routers. You can do like this only if all your stack routers are isomorphic to each other (has the same routes and configs), then potentially your can raise event “Reset to HomeScreen” and your root stack and all nested stacks will fall back to their HomeScreen as they all have it. But if your nested stack routers are not isomorphic to your root stack router, there will be an error “There is no route defined for key HomeScreen” caused by some of them. This commit adds “type” property to StackRouter and SwitchRouter and prevents passing down RESET event from SwitchRouter to its nested StackRouters.
I've tested everything again and the bug could be fix by changing
to
in @ericvicenti, @brentvatne should I update this pr? |
It's just I am not sure what is the expected behaviour for reseting navigation. Maybe you want user to be able to reset some part of app navigation without updating anything else (partial reseting)? Then we should only fix |
So, this may be a documentation/types problem, but it looks like your reset action is lacking a key.
Exactly right. The key is provided to target which stack needs to be reset. By specifying the key, the behavior will not get passed down to children routers. |
So I don't think this change is necessary. But we should make it clear that |
fwiw "reset" is a bit awkward and i'd really love for this to be implemented: react-navigation/rfcs#70 |
@ericvicenti Ok, I understand. This seems like a breaking change, as I don't remember that "key" was required before, and without the "key" navigation can crash depending on the screen where you try to use Maybe we can just work with
Another question, why does |
@serhiipalash - i think the best option here is to change the |
I made a new pr #44 I tested its changes in https://github.com/serhiipalash/test-react-navigation-reset and everything works fine both when key is missing (root stack is reseted) and when it is set to nested navigator key (Profile stack is reseted). |
This pull request fixes the error
"There is no route defined for key..."
when you supply RESET event to your root StackRouter and it is passed down to one of your nested StackRouters.Bug:
video: https://drive.google.com/file/d/1QJvZ_C47xLAfXpb6YJfwFQsT2XRSf5Mv/view
snack: https://snack.expo.io/@serhiipalash/test-react-navigation-reset
repo: https://github.com/serhiipalash/test-react-navigation-reset
screenshot:
There is no sense to spread root StackRouter RESET event to all nested StackRouters. You can do like this only if all your StackRouters are isomorphic to each other (have the same routes and configs). In that case potentially your can raise event “Reset to HomeScreen” and your root StackRouter and all your nested StackRouters will fall back to their HomeScreen as they all have it. But if your nested stack routers are not isomorphic to your root stack router (more realistic case), there will be an error “There is no route defined for key HomeScreen” caused by some of them.
This pull request adds “type” property to StackRouter and SwitchRouter and prevents passing down RESET event from SwitchRouter to its nested StackRouters.
To test this fix
video: https://drive.google.com/file/d/1QtHU4SqC0KlTA_9Bn_SZyu08ol7JHaqD/view
P.S. I am not sure why, but the bug happens only when you dispatch RESET event from SwitchRouter screen. When you do the same on one of root StackRouter screens, everything works fine.
https://drive.google.com/file/d/11PcjeIVmEieVJ-Ccw03rKae0hRiIst_x/view
P.P.S @ericvicenti can you please review this pr? If you remember, you reviewed one of my pr for fixing navigation reseting react-navigation/react-navigation#3593.