Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty bridge-components in default userAgent #64

Open
EmilioCristalli opened this issue Oct 16, 2024 · 2 comments
Open

Empty bridge-components in default userAgent #64

EmilioCristalli opened this issue Oct 16, 2024 · 2 comments

Comments

@EmilioCristalli
Copy link

I was trying to follow the docs to create a bridge component, but i think the component wasn't loading because the default user agent is sending an empty list of components (bridge-components: [];)

If I understand correctly, hotwire-native-bridge checks that the list is not empty here to decide if the component should load.

If the user agent is overridden with something like Hotwire.config.userAgent = "MyApp; ${Hotwire.config.userAgentSubstring()}", the user agent now includes the right bridge-compoennts, and the component loads correctly.

Not sure if this is a bug or if i missed something in the docs, but it felt like the default userAgent should just work.

Was also able to reproduce this int he demo app, by commenting out the custom userAgent line here. After doing this, the bridge components stop working

@donnfelker
Copy link
Contributor

donnfelker commented Nov 4, 2024

I had this same problem for a bit. The hotwire-native-bridge does expect that the array be non-empty. Which kind of makes sense if you think about it. If there are not bridge components registered then there is no reason to even load them on the client and waste potential resources. The client is telling the rails app "Hey, I can handle these bridge components". If your app is not using bridge components, then there's no reason for it to connect the stimulus controllers.

I can see why you'd want it to work by default, so maybe setting the Hotwire.config.userAgent by default to the substring might suffice?

@EmilioCristalli
Copy link
Author

yeah, i think it makes sense that hotwire-native-bridge requires a non-empty array to initialize the components.

What was unexpected to me was that hotwire-native-android wouldn't send these components by default, even after registering the bridge components with Hotwire.registerBridgeComponents

Looking at this code

    fun userAgentSubstring(): String {
        val components = registeredBridgeComponentFactories.joinToString(" ") { it.name }
        return "Turbo Native Android; bridge-components: [$components];"
    }

    var userAgent: String = userAgentSubstring()

it made me think the intention was that, by default, the userAgent should include all the registered bridge components, but maybe this default is being evaluated before the components are registered, so the array ends up being empty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants