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

When the initial page redirects, the BridgeDelegate.location becomes stale #23

Closed
adampal opened this issue Nov 26, 2023 · 5 comments · Fixed by #24
Closed

When the initial page redirects, the BridgeDelegate.location becomes stale #23

adampal opened this issue Nov 26, 2023 · 5 comments · Fixed by #24

Comments

@adampal
Copy link

adampal commented Nov 26, 2023

When the very first URL loaded by a Turbo.VisitableViewController is redirected by the Rails app, the location constant in the BridgeDelegate is set to the initial URL, not the redirected URL. As a result, any BridgeComponents on the page will ignore messages because the location does not match the message.metadata?.url.

Any subsequent page loads, even if they include redirects, will set the location correctly and BridgeComponents will work.

I created minimal Rails and iOS repos to reproduce the bug. The Rails repo is a basic rails new with all the defaults and really just adds the bridge--hello controller and views.

The iOS repo starts from the Strada-iOS demo and just adds a helloComponent.

Each repo only adds a single commit (rails commit, iOS commit) so it's easy to see what I've added/changed to reproduce the bug.

If you clone the repos and run it locally, you can toggle the behaviour by setting the Demo.current in the iOS repo to either local or noRedirect:

  • when set to noRedirect the rootURL is set to the URL of the first page. The app will load and the BridgeComponent is loaded and works correctly.
  • when set to local the rootURL is set to a different URL that redirects to the URL of the first page of the app.

Even though they both end up on the same page, in the local version the BridgeComponent will ignore messages because of the stale location attribute.

You can test subsequent page loads by clicking the links in the nav at the top. All subsequent page loads work correctly, whether they redirect or not.

From looking at the Strada debug logs, it seems that when a URL is redirected, we are supposed to get all lifecycle callbacks triggered twice. Once for the initial URL then again for the final destination URL. However, when the very first URL of the application redirects, this doesn't happen and we just end up with one set of lifecycle events.

I think this may actually be a bug in the Turbo-iOS adapter not here in Strada, but I'm hoping someone with more knowledge than me can point me in the right direction of where/how to get it fixed.

@joemasilotti
Copy link
Member

Confirming that this is reproducible and I'd love to get it fixed!

joemasilotti added a commit that referenced this issue Dec 7, 2023
If a Turbo request is redirected to a page with a Strada component this
check would always fail. `location` is only set when `BridgeDelegate` is
initialized. This change dynamically grabs the URL from the web view,
falling back to the original `location` if nil.

Fixes #23
@joemasilotti
Copy link
Member

@adampal, can you give #24 a go and see if it fixes the issue for you?

@adampal
Copy link
Author

adampal commented Dec 8, 2023

Amazing...thanks Joe, let me take it for a spin and let you know how it goes.

@adampal
Copy link
Author

adampal commented Dec 14, 2023

@joemasilotti can confirm #24 fixes this issue!

@joemasilotti
Copy link
Member

Excellent, thanks @adampal!

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

Successfully merging a pull request may close this issue.

2 participants