turbolinks / turbolinks-ios

Native iOS adapter for building hybrid apps with Turbolinks 5
MIT License
880 stars 92 forks source link

Update Visitable.visitableURL after following a redirect #156

Open calleluks opened 5 years ago

calleluks commented 5 years ago

Hi!

When reloading a page using pull-to-refresh after visiting a URL that redirects somewhere else, the original URL is reloaded instead of the URL that was redirected to.

This is inconsistent with how Turbolinks works in a browser where the address bar is updated using the History API causing reloading the page to reload the URL that was redirected to.

This happens both for cold boot visits and JavaScript visits.

This PR is an attempt to solve this problem by having the Turbolinks WebView adapter report back the final location after loading a page (for cold boot visits) or completing a visit (for JavaScript visits).

This might be a terrible solution but maybe it can help illustrate the problem?

I've also created a minimal Rails app that can be used to test this by changing ApplicationController.url to point to port 3000 in the demo app:

 import Turbolinks

 class ApplicationController: UINavigationController {
-    fileprivate let url = URL(string: "http://localhost:9292")!
+    fileprivate let url = URL(string: "http://localhost:3000")!
     fileprivate let webViewProcessPool = WKProcessPool()

     fileprivate var application: UIApplication {

When the demo app starts it will first GET / that will redirect to /redirect_target causing another GET for this path.

Before this PR, reloading the page using pull-to-refresh, would cause the same series of requests: GET / then GET /redirect_target.

After this PR, it only causes a GET /redirect_target.

The exact same behavior can be observed when clicking the "Go to /" link causing a JavaScript visit instead of a cold boot visit.

henrik commented 4 years ago

Pinging the Turbolinks devs. I've worked with Calle on our project using Turbolinks iOS and we're about to resume work on it :)