-
Notifications
You must be signed in to change notification settings - Fork 433
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
Add [method]
and [scroll]
attributes for Refresh Stream
#1208
base: main
Are you sure you want to change the base?
Conversation
@adrienpoly I've opened this in response to our conversation in Discord. |
I feel that the I'm less confident about the Visit options key (and resulting property name). The "public API" boundaries of Visit options are currently unclear. If we intend for these keys to be private and for internal use only, the name isn't important to decide upon. If they're intended to be public, I think it's important to workshop and appropriate name and structure. @jorgemanrubia does this seem like a conservative enough expansion of Morph Refresh support? |
Thanks, I am trying to understand how I could leverage in my Rails app and it is a bit unclear. A simplify version of what I have is class Post
broadcast_refreshes
...
end and a view view <%= turbo_stream_from @post %>
<%= turbo_refreshes_with method: :morph, scroll: :reset %>
<form ....></form> The form redirect to this page with a scroll reset and I would like to preserve the scroll when the refresh is triggered by a broadcast. Looking at your proposal I am not sure how I should set the turbo-stream attributes? Would it be something like this? <%= turbo_stream_from @post, scroll: :preserve %> or at the model level? Thanks |
To support scroll resets from redirects during a form submission, you could continue to render the To support scroll preservation from broadcasts, the idea would be to broadcast the Since this change must be made separate from the Rails code, that support is still unclear and to be determined. One possibility could be to extend broadcast_refreshes scroll: :preserve Another approach might be to keep |
56ffe7d
to
99d0755
Compare
> I have a page where I am using Turbo morph. when I submit a form and > redirect I would like to reset the scroll, but if a refresh is triggered > by a broadcast I would like to preserve teh scroll. Is that possible ? > > [#turbo Discord][discord] This commit expands the set of attributes for `<turbo-stream action="refresh">` to include `[method]` and `[scroll]` (in addition to `[request-id]`). These attributes correspond directly to the [`turbo-refresh`-prefixed `<meta>` element][meta] elements that control morphing and scroll preservation. When present on the `<turbo-stream action="refresh">`, their values are forward along to the `Session.refresh` method call, which in turn encodes them into Visit options under the `refresh` key. Those options are then used during `Visit` instantiation, and transformed into `.refresh` properties. At render time, the `PageRenderer` attempts to read the refresh method and scroll preservation settings with the following precedence: 1. read from the corresponding `Visit.refresh` property (possibly null) 2. read from the corresponding `<meta name="turbo-...">` element (possibly null) If no value is provided, fallback to the default (`{ method: "replace", scroll: "reset" }`). [discord]: https://discord.com/channels/988103760050012160/1044659721229054033/1212443786270212167 [meta]: https://turbo.hotwired.dev/handbook/page_refreshes#morphing
99d0755
to
2ccb92e
Compare
@jorgemanrubia are you able to review this proposal? |
This commit expands the set of attributes for
<turbo-stream action="refresh">
to include[method]
and[scroll]
(in addition to[request-id]
). These attributes correspond directly to theturbo-refresh
-prefixed<meta>
element elements that control morphing and scroll preservation.When present on the
<turbo-stream action="refresh">
, their values are forward along to theSession.refresh
method call, which in turn encodes them into Visit options under therefresh
key. Those options are then used duringVisit
instantiation, and transformed into.refresh
properties.At render time, the
PageRenderer
attempts to read the refresh method and scroll preservation settings with the following precedence:Visit.refresh
property (possibly null)<meta name="turbo-...">
element (possibly null)If no value is provided, fallback to the default (
{ method: "replace", scroll: "reset" }
).