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

BUG: The turbo:frame-load event is fired before window.location is updated when using turbo-action="advance" #651

Closed
rathboma opened this issue Jul 27, 2022 · 3 comments

Comments

@rathboma
Copy link

To perform some actions when the turbo frame has finished loading and the URL has changed is currently not possible.

When turbo-frame-load fires, the window.location has not yet been updated, so checking window.location.* still gives the old URL.

Steps to reproduce:

function logEvent(event) {
  console.log("comparing src vs window:", event.target.src, window.location.href)
)

document.documentElement.addEventListener('turbo:frame-load', logEvent)
@rathboma rathboma changed the title BUG: The turbo:frame-load event is fired before the URL changes when using turbo-action="advance" BUG: The turbo:frame-load event is fired before window.location is updated when using turbo-action="advance" Jul 27, 2022
@seanpdoyle
Copy link
Contributor

Thank you for opening this issue!

Is this potentially a duplicate of #617, which might be resolved by #618? #618 is merged, but not yet released.

@rathboma
Copy link
Author

I checked out the issue. It's similar but not exactly the same -- regardless of whether you change location before or after rendering, certainly it should be changed before turbo:frame-load fires.

That fix might fix it, I have a hard time knowing -- does that change the behavior to address #617? If so it probably will

@seanpdoyle
Copy link
Contributor

I've just tested this locally to confirm that it has been resolved by #618.

It's covered by a test that makes the same check during the turbo:frame-render event, which is dispatched before the turbo:frame-load event.

@dhh dhh closed this as completed Aug 1, 2022
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

3 participants