You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After debugging a few new Hotwire Native apps I've noticed a common issue. Hotwire.registerBridgeComponents()must be called before a Navigator 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:
import HotwireNative
import UIKit
let rootURL = URL(string: "https://hotwire-native-demo.dev")!
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
- private let navigator = Navigator()+ private lazy var navigator = Navigator()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
+ Hotwire.registerBridgeComponents([...])
window?.rootViewController = navigator.rootViewController
navigator.route(rootURL)
}
}
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:
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: