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

Ensured re-rendering the stack uses the latest scene and props #637

Merged
merged 1 commit into from
Sep 2, 2022

Conversation

grahammendick
Copy link
Owner

Fixes #635

Was using let { current: allScenes } = useRef but this created a stale closure. It meant the NavigationStack didn't get the latest scene and props from its children. For example, conditional navigation, where dynamically configure the stack of scenes, didn't work. Changing to const const allScenes = useRef fixed it.

But noticed another problem where allScenes was a tempo behind because it was updated in useEffect. So it would take an additional render for NavigationStack to have the latest scenes and props. For example, this wouldn't render 'true'.

const [updated, setUpdated] = useState(false);
useEffect(() => {
  setTimeout(() => {
    setUpdated(true);
  });
}, []);
<NavigationHandler stateNavigator={stateNavigator}>
  <NavigationStack>
    <Scene stateKey="example"><Text>{updated}</Text></Scene>
  </NavigationStack>
</NavigationHandler>

Changed allScenes from ref to const and built it during render instead of waiting for useEffect.

Strangely the same code in NavigationMotion didn't have the stale closure. Well, it was stale but by the time renderScene happened it had the latest scenes and props. But updated NavigationMotion to ensure it never has a stale closure.

Destructuring allScenes from current created a stale closure. So the renderScene didn't have the latests scenes and props. Changing it to allScenes.current throughout did work. But there was still a problem that allScenes updated in useEffect so it was always behind. Need allScenes to be updated as part of the render so it reflects the latest scenes in children
@grahammendick grahammendick merged commit 14fd7e9 into master Sep 2, 2022
@grahammendick grahammendick deleted the issue-635 branch September 2, 2022 18:58
@grahammendick grahammendick changed the title Ensured re-rendering the NavigationStack uses the latest scene and props Ensured re-rendering the stack uses the latest scene and props Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-rendering the NavigationStack should use the latest scene and props
1 participant