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

Fix refresh behavior #220

Merged
merged 2 commits into from
Jul 12, 2024
Merged

Fix refresh behavior #220

merged 2 commits into from
Jul 12, 2024

Conversation

olivaresf
Copy link
Member

While testing, I found that when a visit with a refresh presentation is proposed, TurboNavigatorHierarchyController will correctly pop (or dismiss) and then ask the session to reload. However, the session does not know that the topmost visitable changed, so a reload will end up reloading the last successfully loaded visit – the visitable that was just popped (or dismissed).

@olivaresf olivaresf requested review from svara and jayohms July 4, 2024 21:40
}

private func refreshIfTopViewControllerIsVisitable(from stack: NavigationStackType) {
if let navControllerTopmostVisitable = navController(for: stack).topViewController as? Visitable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss the best way to pass this refresh message to a non-Visitable view controller.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned on the call, leveraging the PathConfigurationIdentifiable protocol is an option here.

switch navigationStack {
case .main: session.reload()
Copy link
Member Author

@olivaresf olivaresf Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use session.reload() because topmostVisitable does not change when a view controller is popped (or dismissed) programmatically. For example:

  1. Propose visit to URL "/one"
  2. Visit completes, session.topmostVisitable = "one"
  3. Propose visit to URL "/two"
  4. Visit completes, session.topmostVisitable = "two"
  5. Propose visit to URL "/refresh_historical_location" with presentation: refresh
  6. Visitable with visitableURL = "/two" is popped.
  7. session.reload() is called, which reloads the topmost visitable ("/two" set during step 4).

@olivaresf olivaresf force-pushed the fix-refresh branch 3 times, most recently from cfa9487 to 23d5ca9 Compare July 4, 2024 23:36
Copy link
Contributor

@svara svara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @olivaresf!
I really like the tests 👌

}

private func refreshIfTopViewControllerIsVisitable(from stack: NavigationStackType) {
if let navControllerTopmostVisitable = navController(for: stack).topViewController as? Visitable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned on the call, leveraging the PathConfigurationIdentifiable protocol is an option here.

@svara svara merged commit 3ce4f97 into turbo-navigator Jul 12, 2024
1 check passed
@svara svara deleted the fix-refresh branch July 12, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants