-
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
Components in turbo-frame are being ignored due to url mismatch #19
Comments
I've also run into this with a response that redirects to a different URL - for example, in my application, the entrypoint URL for the Turbo webview is I've observed the same behaviour with components being ignored due to a URL mismatch after this redirect, since the URL has changed from I've been looking around at how I can update the location myself, but because of how Turbo navigation visits work, I don't think there's a direct WKWebView delegate method I can use, since the URL could be modified by Turbo via |
I've worked around this by forking and removing the assertion that the BridgeDelegate location matches the message metadata URL property. I then removed the package dependency and re-added it using my own repository. I originally tried extending or overriding BridgeDelegate, but the class being final prevents all the overrides I attempted. I would like to arrive at a point where I can submit a PR for this problem, but I'm unsure of what the purpose of the guard is. I'm guessing it's to prevent messages being passed to a component that is part of the view hierarchy, but concealed by something else? Keeping the location more up-to-date in the BridgeDelegate would be a solution, however there are several ways the location could change - it could be redirected, be navigated outside the webview (like using If it is important that the URL gets matched against, it is still possible to access this within each BridgeComponent's |
This is surprising behavior. We heavily use Is the document url changing after loading new |
The strada-web side is fine, it's the stale url that the native bridge delegate is using to validate whether it should ignore the component or not. When we're updating the contents of a frame on an existing page, the bridge is never made aware of the url change. |
Can you enable debug logging in the |
I can, but I'll note I have a slightly different cause of this issue - for me, it's that turbo-ios doesn't seem to be aware of the current webview's updated URL after navigation. Here's what I get from turbo-ios:
Then if I tap on the 'Continue with Google' button (which the BridgeComponent is bound to):
If I add a breakpoint in
So it's like the location that the bridge is aware of is not following when navigation occurs. I've been patching out that guard completely, but now that I look at it, I wonder if I'd be better to check the webView URL at runtime when that guard check occurs instead. Here's what my backend request logs look like:
This flow is based on the Turbo-iOS demo application, specifically catching the 401 response, and then prompting for authentication. Just like the demo application, my sign-in route is configured to open with 'modal' presentation, so I have two sessions in my app - one for the main webview, and another for modals. The session initialisation code for both includes initializing the bridge: public func makeSession() -> Session {
let configuration = Self.makeWKWebViewConfiguration()
let session = Self.makeSession(configuration: configuration)
session.delegate = self
session.webView.uiDelegate = self
Bridge.initialize(session.webView)
return session
} I hope this helps! |
In our case it's as simple as including a turbo-frame in the turbo-native-demo index.ejs and to wrap the strada-menu.ejs in a corresponding turbo frame.
We tried the suggestion from @joshmcarthur and when using the webView.url it allows us to keep the guard in place while still having the bridge delegate work as expected. Though at this time we're also using a version that has completely removed the guard. |
Shot in the dark here… but can you print out the two URLs that are being compared in the |
http://localhost:3000/clients/1 <- holds the turbo-frame and is the original url bound to the bridge delegate's location variable In our case, we have a single turbo frame acting as a dynamic placeholder for our links that give the visual representation of tabs. When you click on a tab, they update the content of the frame and turbo uses the history.pushState to update the url. We need this to allow the pull to refresh function to maintain the tab state. When the new tab html loads into the frame, strada-web uses the current (updated from the pushstate) location when binding the new bridge components, but the bridge delegate associated with the current session/webview is using the stale location variable in the guard as we haven't technically invoked a route proposal. |
I'd imagine this is also going to affect someone who is using a lazy-loaded turbo frame (or in fact multiple turbo-frames on a page that navigate to different places), since strada-web is using the URL from the I'd still be quite curious to know the purpose of the guard - I've guessed it's to stop components running on the wrong webview? |
Hi there, I hit the same issue with In my case its pretty simple in that when the app launches the WebView visits In that case the Strada component is not rendered. Interestingly if I navigate away in the same view then hit the NavigationController "back" button, the component is now rendered fine. Only that first load is not working. Also, other tabs that do not redirect render the components as expected |
I have the same issues with |
I had something similar to this and the difference was the trailing slash at the end of the url (url with trailing slash works fine). No slash:
With slash:
|
There seem to be 2 separate issues in this thread:
Given the title of this issue is for turbo-frames, I created a new issue (#23) with my investigation of the stale |
Hey folks, can you give PR #24 a try? Thanks to @joshmcarthur for the idea of grabbing the URL at runtime! |
Resolved via #24. |
We have "tabs" in our app. Basic links that swap the contents of a turbo-frame. We have bridge components included in the content that gets dynamically loaded into the frame based on the tab you click. They're being ignored because the bridge's location doesn't match the metadata's url in bridgeDidReceiveMessage https://github.com/hotwired/strada-ios/blob/main/Source/BridgeDelegate.swift#L118 which appears to be the url from the link initiating the request, whereas the bridge location is still based on the initial page visit.
We tried this with the turbo-native-demo and experienced the same results with the menu controller.
What's the expectation here? Is there a way around this for the time being, or have we implemented something incorrectly? We don't really see anything in the documents around this. Just a comment in the strada-web library.
// Include the url with each message, so the native app can
// ensure messages are delivered to the correct destination
Thanks!
The text was updated successfully, but these errors were encountered: