Introduce refresh
visit action and method to refresh the current page
#1186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issues:
turbo:load
event was caused by a refresh #1150This PR adds a
refresh
visit action and changesSession#refresh
to use the current URL if not provided explicitly.Add
refresh
visit actionThe motivation behind it is to support more granular behavior when doing refreshes. Today, a 'refresh' is essentially a
replace
action to the current URL. There's no easy way to know if this action was triggered by a user interaction or by a turbo stream refresh. By adding a granularrefresh
action, developers can handle refreshes (eg. broadcasted as streams) differently from replace actions (form submissions, drive navigations, ..).An example of this would be in Turbo iOS, where there's no way to differentiate between a user-triggered
replace
action (ie. pull-to-refresh) or a programatically triggered refresh (ie. broadcasts) (see eg. Turbo iOS #136 and Turbo iOS #175).With this change, developers (and library maintainers of eg. Turbo iOS) would able to differentiate between
replace
actions andrefresh
actions and handle eg. showing loading indicator behavior differently. As an example we'd like show a more subtle loading indicator on refresh actions than on replace actions.Make
Session#refresh
refresh current page unless specifiedSecondly, the
Turbo.session.refresh(..)
method is updated to use the current URL of the page. This allows developers to programatically refresh the current page simply by callingTurbo.session.refresh()
without having to explicitly provide the current page's URL.A common use-case could be refreshing (and morphing) a page when it becomes re-focused as a tab, to always ensure that the content is up to date:
I think this would also be usable for Turbo iOS and Turbo Android apps with multiple sessions, where other sessions could be refreshed instead of reloaded when a mutating request has been made in a single session. See: hotwired/turbo-ios#150