Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Make sure finishRequest() is always called for cold boot visits #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

calleluks
Copy link

Hello and thanks for a great framework!

In a Turbolinks app I'm currently working on, we display multiple navigation controllers in a tab bar controller. Each navigation controller has their own Session but share the same WKProcessPool.

When showing and hiding the network activity indicator in response to receiving sessionDidStartRequest(_:) and sessionDidEndRequest(_:) messages, I found that sessionDidEndRequest(_:) wasn't called if I switched to a different tab before the request hda finished. Since we're using reference counting to show and hide the indicator, this caused the indicator to never be hidden.

In 11d71c3, I have made some changes that make this easier to reproduce: just start the demo app, switch to the second tab, and watch the printed messages in the Xcode debugger output pane.

We should make sure to remove this commit before merging if you decide doing so makes sense.

The reason sessionDidEndRequest(_:) isn't called is the the WKWebView won't send the webView(_:didFinish:) message to its navigationDelegate (i.e. the ColdBootVisit) after switching to a different tab. I don't know why it doesn't do so and can't find any documentation describing this behavior.

In 4515ceb, I add a call to finishRequest() in ColdBootVisit.completeVisit() to fix this problem. Since finishRequest() only calls sessionDidEndRequest(_:) once and we know that the request must have finished at this point I think this should be safe.

Let me know what you think!

When doing a cold boot visit, `finishRequest()` was previously only
called in response to receiving the `webView(_:didFinish:)`
`WKNavigationDelegate` message. If the web view wasn't on screen when
the navigation finished—for example after the user switched to another
tab in a parent `UITabViewController`—`webView(_:didFinish:)` would not
be called, causing the `VisitDelegate` to never be sent the
`visitRequestDidFinish(_:)` message.

Since `finishRequest()` will only call `visitRequestDidFinish(_:)` once,
it should be safe to call it again in `completeVisit()` at which point
the request must have finished since the whole visit has already
completed.
@henrik
Copy link

henrik commented Aug 25, 2020

Pinging the Turbolinks maintainers. I've worked with Calle on this project and we will soon pick it up again :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants