hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
423 stars 51 forks source link

App stops responding if a page redirects more than once on a cold boot #217

Closed ghiculescu closed 2 years ago

ghiculescu commented 2 years ago

If a navigation is proposed from the native layer after calling resetSession(), and there is more than 1 redirect involved, each of which happens within 500ms of the last, the app breaks. To replicate:

Watch this gif:

bug

When you click the web navigation link everything works fine (first click in the gif).

When you click the link with slow redirects, everything works fine (second click).

When you click the link that uses the native handler to propose navigation, the navigation fails (third click).

Workarounds

In terms of workarounds: if you don't call resetSesssions here, the issue is resolved. So the issue only happens when you're on a cold boot path. We need to call resetSessions because in some cases this redirect is been cross-domain and we need to allow that.

Another workaround is adding sleep(0.5) if platform.android? on the server side for this particular code path 😿

This is a hurting my brain, what's the issue?

If you:

An example scenario:

Each of these redirects would need to complete in more than 500ms to avoid the issue.

Possible fix

It'll probably create other issues, but if you remove shouldProposeThrottledVisit or make it return true the issue is resolved. I'm not confident enough about that throttler's purpose to make a PR yet so wanted to get some feedback on the issue.

Another idea would be for shouldProposeThrottledVisit to only happen if there's two attempted to clicks to the same location, not different ones as is the case here.