hotwired / hotwire-native-ios

Hotwire Native for iOS
MIT License
84 stars 10 forks source link

Redirect to replace_root hits server twice #31

Open MichalSznajder opened 2 months ago

MichalSznajder commented 2 months ago

Suppose we have in path_configuration:

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 commented 2 months ago

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 https://github.com/hotwired/hotwire-native-ios/pull/24. What happens if you try your scenario with that branch?

MichalSznajder commented 2 months ago

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

https://github.com/hotwired/hotwire-native-ios/blob/9c7d6c263a528c0a02e3796a5f451eb8405e2107/Source/Turbo/Navigator/NavigationHierarchyController.swift#L188-L195

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