Closed jayohms closed 1 month ago
Good call. Making a comment for others in case they run into this ...
I just ran into this issue this morning. Server was looking for Turbo Native Android
in the web bridge that I had installed. Therefore the stimulus controller was not connecting.
Other thing that tripped me up was that I had my code to replace the user agent value (RE: #66) set up BEFORE, I registered my BridgeComponent
s, therefore, I was getting a user agent that looked like this:
Hotwire Native Android; bridge-components: []; Mozilla/5.0 (Linux; Android 14; sdk_gphone64_arm64 Build/UE1A.230829.036.A4; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/129.0.6668.100 Mobile Safari/537.36
Due to the bridge-components
array being empty, the isHotwireNativeApp
in the Hotwire Bridge Component JS file would return false, therefore the bridge would not connect.
Note for others - When setting up Android Hotwire in your app, the user agent needs to be set after you register the bridge components, like this:
// Register Bridge Components
Hotwire.registerBridgeComponents(
BridgeComponentFactory("form", ::FormComponent)
)
// Needs to happen after bridge components are registered as the
// user-agent sends up the list of registered components in the user agent.
// `replace()` call needed until: https://github.com/hotwired/hotwire-native-android/pull/66 is merged and released into new version
Hotwire.config.userAgent = Hotwire.config.userAgentSubstring().replace("Turbo Native", "Hotwire Native")
I had mistakenly configured it at the top, above everything else (this was that way from when I was migrating from Turbo/Strada). That wont work 😅
@donnfelker I'll push out a new release so this PR is included in the latest release.
Note for others - When setting up Android Hotwire in your app, the user agent needs to be set after you register the bridge components
I'll think about how we can make this more better from an API perspective to avoid this issue. In the meantime, yes, you'll have to register the bridge components before setting the user agent.
This allows servers to match against
Hotwire Native Android
orTurbo Native Android
user agents. This matches the approach in the iOS library.This is a follow up to https://github.com/hotwired/hotwire-native-android/pull/66