turbolinks / turbolinks-ios

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

double-call of visitableDidRender #49

Closed glennfu closed 7 years ago

glennfu commented 8 years ago

When the app is first loaded, and any time a pull-to-refresh is triggered, visitableDidRender gets called twice. Is this intentional? This is easy to reproduce in the Demo. Just open DemoViewController and add:

    override func visitableDidRender() {
        super.visitableDidRender()
        print("visitableDidRender")
    }

You'll see it get called twice at the times I mentioned. When clicking a link, or navigating back, it's only called once as expected.

Following the callback chain it looks like ColdBootVisit didFinishNavigation gets called, triggering it, and then ColdBootVisit didLoadPageWithRestorationIdentifier gets called, triggering it again.

If this is intentional, is there a way to determine the difference in paths so that I can apply my changes in visitableDidRender only once?

glennfu commented 8 years ago

In my testing, updating Session: VisitDelegate in Session.swift with...

    func visitDidInitializeWebView(visit: Visit) {
        initialized = true
        delegate?.sessionDidLoadWebView(self)
//        visit.visitable.visitableDidRender()
    }

...fixed it for me. Everything seems to work fine after making that change. Are there any downsides to this?

yvonnenieuwerth commented 8 years ago

I seem to be having this problem as well. In my viewDidLoad there is just:

presentVisitableForSession(session, URL: url)

The visitableDidRender gets fired twice. I do wonder what the reason is that the session calls the method both on visitDidRender and visitDidInitializeWebView

packagethief commented 8 years ago

I noticed this problem recently too, and addressed it in #45. Specifically, in https://github.com/turbolinks/turbolinks-ios/pull/45/commits/5598e70. I'll refresh my memory of the PR and merge it soon!

zachwaugh commented 7 years ago

The fix for this has been merged into master and is in 1.0.3.