Fix same page restore visits when returning to a web screen from a native screen
#160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes: #136
Let's say you have 2 screens:
A(web screen)B(native screen)Previously, when you navigated from
A->B-> (back to)A, the library would perform a "synthetic" restore visit to theAscreen, since the underlying session'sWebViewstill resided at locationA(Bis native, so it didn't alter theWebViewlocation).This approach prevented
Afrom recreating it'sViewstate for bridge components on the screen. WhenAis no longer visible, it'sViewis destroyed by the system and onlyBis visible on screen. Additionally, the synthetic restore approach meant that we never cached snapshots when leavingAand visiting a native screen.So, to fix this: I updated the functionality to:
This wasn't sufficient, though, reattaching the
WebViewto the already currently rendered location does not trigger Stimulus to re-connect its controllers. This makes sense, since the page DOM hasn't actually changed. But, it's a problem in the native library since we need to rebuild the view state of the attached bridge components on the screen — and the way to do this is to see theconnect()callback in bridge component controllers on the web.To work around this, the native library now dispatches a
native:restoreevent that the web bridge library can listen to in already connected bridge component controllers and manually call itsconnect()method.This is the corresponding PR to allow native apps to see bridge components reconnect after a synthetic
restorevisit:hotwired/hotwire-native-bridge#9