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

Redirect to replace_root hits server twice #31

Open
MichalSznajder opened this issue Sep 26, 2024 · 2 comments
Open

Redirect to replace_root hits server twice #31

MichalSznajder opened this issue Sep 26, 2024 · 2 comments
Assignees

Comments

@MichalSznajder
Copy link

MichalSznajder commented Sep 26, 2024

Suppose we have in path_configuration:

  • /list_items with replace_root, also default URL in app
  • /add_item with with default

Let's execute following step

  1. App starts with /list_items.
  2. User navigates to /add_items
  3. Form is submitted and results in redirect to /list_items
  4. /list_items is hit and visit is proposed via WebViewBridge
  5. Because of path_configuration we end up in NavigationHierarchyController.replaceRoot
  6. New visit is initiated with action=replace, redirected flag is ignored
  7. NOK: /list_items is hit again (resulting in flash being lost)
@olivaresf
Copy link
Member

Hey @MichalSznajder,

New visit is initiated with action=replace, redirected flag is ignored

I suspect this is a known issue that could be fixed with #24. What happens if you try your scenario with that branch?

@olivaresf olivaresf self-assigned this Oct 1, 2024
@MichalSznajder
Copy link
Author

It doesn't help. It is better as NavigationHierarchyController.replaceRoot gets proposal with redirected==true but flag is ignored:

private func replaceRoot(with controller: UIViewController, via proposal: VisitProposal) {
if let visitable = controller as? Visitable {
delegate.visit(visitable, on: .main, with: .init(action: .replace))
}
navigationController.dismiss(animated: proposal.animated)
navigationController.setViewControllers([controller], animated: proposal.animated)
}

I attempted to fix it by passing options created from the proposal, and now the server is no longer being hit twice. Not sure about side effects.

https://github.com/MichalSznajder/hotwire-native-ios/blob/cedea09b969257436f80044e98566f5b7814a05d/Source/Turbo/Navigator/NavigationHierarchyController.swift#L190-L191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants