mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
[Navigator] Guard navigator.state.routeStack from accidental mutation
Summary: A minor improvement suggestion: `Navigator.getCurrentRoutes()` probably shouldn't return its `routeStack` backing array as-is, because the caller may mutate it, causing the internal state of the navigator to go out of sync. Instead a shallow copy of the routes should be returned. I stumbled on this problem in my app by attempting to read the navigator state as follows: ``` let routes = Navigator.getCurrentRoutes(); let current = routes.pop(); let previous = routes.pop(); ``` Which led to an exception at next navigation event. CLA signed. Closes https://github.com/facebook/react-native/pull/1888 Github Author: Jani Evakallio <jani.evakallio@gmail.com>
This commit is contained in:
@@ -1002,7 +1002,8 @@ var Navigator = React.createClass({
|
||||
},
|
||||
|
||||
getCurrentRoutes: function() {
|
||||
return this.state.routeStack;
|
||||
// Clone before returning to avoid caller mutating the stack
|
||||
return this.state.routeStack.slice();
|
||||
},
|
||||
|
||||
_handleItemRef: function(itemId, route, ref) {
|
||||
|
||||
Reference in New Issue
Block a user