hotwired / turbo-ios

iOS framework for making Turbo native apps
MIT License
891 stars 87 forks source link

Snapshots are not taken when VisitableViewController is dismissed (ie. modal session) #180

Closed pfeiffer closed 7 months ago

pfeiffer commented 8 months ago

We've found an issue around how snapshots are being taken when navigating between separate sessions. When navigating between view controllers not belonging to the same session, snapshots are not taken and potentially stale snapshots are being shown.

The most simple example of this issue is actually in the demo app. Adding a delay to the /new action (shown modally) as well as showing a random number highlights the issue. The steps are:

  1. Open the modal demo page (this will use Modal session)
  2. Dismiss the modal
  3. Open the modal demo page - no snapshots are shown, even though the page could already have been snapshotted
  4. Dismiss the modal
  5. Open the modal demo page again - snapshot is now shown, but snapshot is of the page made in step 1, not the latest

https://github.com/hotwired/turbo-ios/assets/195925/950f1db1-11ae-42c0-b56f-c0a57ec913da

What we see here is that opening the modal the second time, still shows a spinner, even though the page has already been loaded and a potential snapshot could have been made when dismissing the modal. Opening it the third time actually does use a snapshot, but the snapshot is of the first visit to the modal, and thus potentially stale.

Since the WebView of the modal session is kept around, I'm wondering if we could somehow signal to the WebView that it's VisitableViewController is being dismissed so that a snapshot could be made?

pfeiffer commented 8 months ago

Added a fix in #181