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

Restore attribute "refresh=morph" to flag turbo frames to reload during a page refresh #1068

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

jorgemanrubia
Copy link
Member

@jorgemanrubia jorgemanrubia commented Nov 17, 2023

This adds a new turbo-frame attribute: refresh. When its value is morph:

  • It will reload the turbo frame with morphing during a page refresh.
  • It won't update the turbo frame with the server response.
  • It won't remove it if it's missing in the server response.

An example where these frames are useful is pagination, or any scenario where you load new state in the screen that you want to preserve during page refreshes, but that you also want to reload because the user action might have affected them.

This attribute was part of the original proposal we presented in Rails World, then we removed it, because we thought it wasn't needed. But after testing the library in different scenarios, we've found that assuming certain logic for all the remote frames was problematic. We had to be too clever about what you wanted to do with the frame. The new attribute makes for a simpler story:

  • The default behavior will be the expected one: turbo frames will be morphed as any other element. E.g: if they get a new URL they will be reloaded; if the get deleted in the response, they will disappear, etc.
  • You can use the new attribute to flag the frames for which you want the special behavior.

Follow up to #1019.

…ng a page refresh.

This adds a new turbo-frame attribute: `refresh`. When its value is `morph`:

* It will reload the turbo frame with morphing during a page refresh.
* It won't update the turbo frame with the server response.
* It won't remove it if it's missing in the server response.

This attribute was part of the original proposal we presented in Rails World, then
we removed it [1], because we thought it wasn't needed. But after testing
the library in different scenarios, we've found assuming certain behavior for all
the remote frames was problematic since it implied being too clever about what
you wanted to do with the frame. The new attribute makes for a simple behavior:

* The default behavior will be the expected one: turbo frames will be morphed
as any other element. If they get a new URL they will be reloadded, if the get
deleted in the response, they will disappear, etc.
* You can use the new attribute to flag the frames for which you want the special
behavior.

[1]: 0c6a95d
Copy link
Collaborator

@afcapel afcapel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jorgemanrubia jorgemanrubia merged commit 528dfdc into main Nov 17, 2023
2 checks passed
@jorgemanrubia jorgemanrubia deleted the flag-to-reload-frames branch November 17, 2023 12:30
@krschacht
Copy link
Contributor

@jorgemanrubia I noticed that when you put refresh="morph" on a turbo frame and trigger it's refresh with element.reload() it does not morph. In this case, it falls back to a full reload of the frame. I'm thinking this may have been an oversight of the implementation.

In my testing it only morphs when the full page is doing a morphing refresh.

@jorgemanrubia
Copy link
Member Author

@krschacht yes I agree that that would be more consistent. I'd appreciate if you can create an issue 🙏 .

@krschacht
Copy link
Contributor

Done. Issue #1161 is tee'd up with a good example.

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

Successfully merging this pull request may close these issues.

3 participants