hotwired / turbo-ios

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

Reload or recreate web view when its process is terminated #187

Closed svara closed 8 months ago

svara commented 8 months ago

This PR improves handling of the terminated web view processes which leave the web views with a white screen.

@zoejessica did a thorough investigation on this topic. The following is taken from one of our PRs at 37signals.

You can read more here, but tl;dr we suspect that there are three ways web views can become blank, either:

  1. they are killed in the "normal" way in the background through memory pressure, the delegate method fires, and they can then be reloaded, or
  2. they are killed by the system without triggering a delegate callback, but can be recovered with a reload, or
  3. they are killed by the system in a way that leaves them non-recoverable with a reload.

This PR takes care of all three cases.

TurboNavigator needs to track the app's state (active or background) in order to decide when to reload the terminated web views. To facilitate this, I've added two public functions: appDidBecomeActive() and appDidEnterBackground().