-
Notifications
You must be signed in to change notification settings - Fork 10
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
Bridge components aren't always registered #35
Comments
What do you think about this #41? In #41, all Navigators will subscribe to a Could you take that for a spin in one of your projects to see if it works for you? |
This works great! I swapped out In-flight requests, as expected, do not correctly register their bridge components. You can replicate with the code below. But I'm OK with not addressing that - what do you think? import HotwireNative
import UIKit
let rootURL = URL(string: "http://localhost:45678")!
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
private let navigator = Navigator()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
window?.rootViewController = navigator.rootViewController
navigator.route(rootURL)
Hotwire.registerBridgeComponents([FormComponent.self])
}
}
final class FormComponent: BridgeComponent {
override class var name: String { "form" }
// ...
} |
OMG, thanks for posting this. I have been trying to get bridge components working for hours, tried so many weird things, but it turns out I just needed to register the components earlier. I was going to suggest updating the documentation to mention this, but if there is a potential fix on the way maybe it's best to just ship the fix sooner. Hmm... well right now the guide says:
It could be changed to say "before creating your navigator" or something... but again, if the bug will be fixed soon then maybe it's not worth adding that caveat. |
After debugging a few new Hotwire Native apps I've noticed a common issue.
Hotwire.registerBridgeComponents()
must be called before aNavigator
instance is created. Otherwise, the bridge components never register for the web view.The quick fix is to defer creation of the
Navigator
via a lazy variable, like so in the getting started guide:However, it isn't clear why this has to occur and isn't documented anywhere.
I don't think we can ever get
registerBridgeComponents()
to work after a URL has been routed. The user agent can't be changed after the request is made and that is what signifies which bridge components are registered. However, having a warning or error if you try to register after a URL has been routed could go a long way in stopping these issues.I'm also open to other suggestions if folks have ideas!
The text was updated successfully, but these errors were encountered: