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

add public method to allow clearing the turbo session cache #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yanshiyason
Copy link

I'm encountering an issue with my UITabBarController-based app related to navigation state and Turbo session cache behavior.

Scenario

  • Tab A Navigation Stack:

    1. /posts (index page)
    2. /posts/1 (show page)
  • Tab B Navigation Stack:

    1. /posts (index page)
    2. /posts/1 (show page)
    3. /posts/1/edit (edit page, where a POST request is made)
    4. Back to /posts/1 (show page)
      • The Turbo session cache is busted, and the back button now shows updated data on the index page.

Issue

After interacting with Tab B and returning to Tab A:

  1. Tab A’s /posts/1 (show page) is updated as expected because the navigator executed a Turbo.visit(page.url, {action: 'replace'}).
  2. However, when pressing the back button in Tab A:
    • The /posts (index page) is stale because the Turbo session cache for Tab A’s navigator was not busted.

Having a way to clear the cache manually would fix my issue.

@joemasilotti
Copy link
Member

We added reload() to handle this problem in a slightly different way.

Reloading ensures that the current page stays up to date, too. Not just when you tap the back button.

I’m curious to hear if this solves your problem or you need to only clear the cache.

@yanshiyason
Copy link
Author

Hi Joe, thank you for getting back to me so quickly.

So I tried both approaches, and they don't behave the same. Here is what I found:

Navigation stack:
1. /home
2. /home/top-posts
3. /home/top-posts/1

navigator.reload()

Navigation stack:
1. /home
2. /home/top-posts
3. /home           <-- This changed from current URL to initial URL
Navigation stack:
1. /home
2. /home/top-posts
3. /home/top-posts/1

navigator.invalidateSessionCache()
navigator.route(VisitProposal(url: url, options: VisitOptions(action: .replace)))

1. /home
2. /home/top-posts
3. /home/top-posts/1  <-- This is still the current URL

So apparently, session.reload() loads the URL the session was initially loaded with, not the current URL in the webView.

@joemasilotti
Copy link
Member

Hmm, that doesn't seem correct. I can't reproduce in the demo app. I added a button to call navigator.reload() in the demo app and it kept the current stack.

Are you sure there isn't anything going on on your server to redirect a page?

If you can reproduce in the demo app please let me know.

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