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

Remove complete state from lazily-loaded frame #1066

Closed
wooly opened this issue Nov 15, 2023 · 5 comments
Closed

Remove complete state from lazily-loaded frame #1066

wooly opened this issue Nov 15, 2023 · 5 comments

Comments

@wooly
Copy link

wooly commented Nov 15, 2023

Is it possible to remove the complete state from a lazily-loaded frame, so that the next time it becomes visible, it will request its content again?

Whenever I try to removeAttribute('complete') on the frame, the complete changed observer here:

completeChanged() {
if (this.#isIgnoringChangesTo("complete")) return
this.#loadSourceURL()
}
immediately re-requests the url, which is undesirable. I'd like to reset it to the same behaviour that it has when the page first loads (i.e. not-complete and empty).

I've tried setting the src to an empty string and then back again, but this still loads the content as part of the srcUrlChanged callback.

@brunoprietog
Copy link
Collaborator

Fixed in #1175

@wooly
Copy link
Author

wooly commented Jul 22, 2024

Hi @brunoprietog, I've just gotten round to upgrading to turbo 8.0.5 (I think this was closed as part of 8.0.4), but I'm still experiencing this issue. As soon as I removeAttribute("complete"), it just gets added in again straight away.

My use case is a dropdown menu that contains a turbo frame. Whenever the dropdown menu opens, the turbo frame should be requested. When the dropdown menu closes, the turbo frame is cleared and the complete attribute is removed, so that it is re-requested the next time the dropdown menu opens. When I upgrade to 8.0.5, the turbo frame is not requested and my dropdown stays empty.

@brunoprietog
Copy link
Collaborator

Could you show some code? Anyway, the complete attribute is not intended to be used that way. Instead, you could reload the Turbo frame maybe? Delete the contents of the Turbo frame with something like frame.replaceWith() and frame.src = null.

The complete attribute is read-only

@wooly
Copy link
Author

wooly commented Jul 22, 2024

I'll work up a little example if I can replicate the behaviour, definitely yep.

Hmm, the intention is not to reload the frame but to cause it to reset back to what it was before it was fetched, so when the element becomes visible again, it will trigger the fetch again.

@brunoprietog
Copy link
Collaborator

There's a better way to accomplish the same thing. Check this example:

<a href="/menu" popovertarget="menu" data-turbo-frame="menu" role="button">Menu</a>
<turbo-frame id="menu" popover></turbo-frame>

Each time you click on the link, the Turbo frame will reload from the URL/menu. If you click outside or press escape, the menu will close automatically thanks to the popover attribute.

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

2 participants