hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
407 stars 51 forks source link

Ensure that a snapshot is cached before navigating to a new location #303

Open jayohms opened 4 months ago

jayohms commented 4 months ago

This is the Android counterpart to: https://github.com/hotwired/turbo-ios/pull/181

Prior to this PR it was possible that a snapshot was not cached for a given page when navigating away from a WebView screen. Replication steps:

  1. Visit native screen A
  2. Navigate to web screen B
  3. Dismiss web screen B and navigate back to the native screen A
  4. Navigate to web screen B again. There was no snapshot cache available.

This is due to the fact that, historically, snapshots were only cached by core turbo.js when navigating from web -> web screens. This resolves the issue by always caching a snapshot before navigating away from a web screen.

pfeiffer commented 4 months ago

Looks great!

In the https://github.com/hotwired/turbo-ios/pull/181 I added a delegate method to deactivate the Visitable when the VisitableView did disappear; the thought was that we could end up with an active, but orphaned Visitable for the session, eg. when a modal is dismissed, it's WebView would still stay active, potentially receiving Turbo Streams etc. in the background, which feels off. We'd rather prepare the screenshot until next visit in that session.

Is there a similar need for such a thing in the Android library? TBH I'm not that familiar with the Turbo Android implementation, as we've primarily re-implemented most of it in the React Native Turbo library due to TurboSession marked as private.

jayohms commented 4 months ago

There shouldn't be any similar concerns in the Android library, since the WebView already gets properly detached/deactivated before navigating away from a Fragment. And, the Android library does not use separate modal vs default sessions like iOS, so there aren't the same concerns there, either.