hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
431 stars 49 forks source link

Error on refresh when export Turbo with <script type="module-shim"> #156

Closed fffx closed 3 years ago

fffx commented 3 years ago

When I use module-shim to export Turbo to global scope, everything works fine in the native browser

<script type="module-shim">
  import { Turbo } from "/assets/turbo-3ef5e39982a514d8e2ede826883b09874c37a36966ecf57237a2062b484821bd.js"
  window.Turbo = Turbo // for turbo native
</script>

but in Turbo android, I will get to the error page sometimes when I trigger a pull refresh, the log says TurboIsReady is false, but if I keep refreshing, it will come back, and then error, come back, error, go on and go on.

D/TurboLog: turboIsReady ...................... [session: main, isReady: false]
D/TurboLog: reset ............................. [session: main]
D/TurboLog: visitRequestFailedWithStatusCode .. [session: main, visitIdentifier: , visitHasCachedSnapshot: false, statusCode: 0]
D/TurboLog: turboFailedToLoad ................. [session: main]
D/TurboLog: reset ............................. [session: main]

Though I have fixed this by download https://unpkg.com/browse/@hotwired/turbo@7.0.0-beta.4/dist/turbo.es2017-umd.js, and include it by javascript_include_tag 'turbo.es2017-umd', I still wanna to know why this happens.

jayohms commented 3 years ago

Is your <script> tag located in the <head> of your document? window.Turbo must be available immediately on page load.

fffx commented 3 years ago

Yes, the <script> is definitely located in the <head> of my document. The reason may be caused by type="module-shim" is async loading