Add turbo_visit action#335
Open
myabc wants to merge 2 commits into
Open
Conversation
Wraps `Turbo.visit(location, { action })` with `location` and
`turbo-action` attributes (defaults: "/" and "advance").
Closes marcoroth#18.
There was a problem hiding this comment.
Pull request overview
Adds a new Turbo Stream action, turbo_visit, to allow stream-driven client-side navigation via Turbo.visit(location, { action }), complementing the existing Turbo-related stream actions.
Changes:
- Implemented and registered the
turbo_visitstream action in the Turbo actions module. - Added test coverage validating
locationdefaulting andturbo-actionoption handling. - Documented the new action in the README’s Turbo Actions list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/actions/turbo.ts |
Adds turbo_visit action and registers it alongside other Turbo actions. |
test/turbo/turbo_visit.test.js |
Introduces tests for turbo_visit covering location fallback and action option handling. |
README.md |
Documents the new turbo_visit action in the Turbo Actions section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+26
to
+34
| export function turbo_visit(this: StreamElement) { | ||
| const location = this.getAttribute("location") || "/" | ||
| const turboAction = (this.getAttribute("turbo-action") || "advance") as Action | ||
| const options: Partial<VisitOptions> = { | ||
| action: turboAction, | ||
| } | ||
|
|
||
| window.Turbo.visit(location, options) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
I'm not sure about this. A handful of options:
- follow Copilot's suggestion - for parity with
redirect_to - no guard - symmetry with
turbo_clear_cache - a simpler guard:
if (window.Turbo) {
window.Turbo.visit(location, options)
}I'd personally opt for 2..
Map the `turbo-frame` attribute to `Turbo.visit`'s `frame` option, mirroring `redirect_to`. Also cover the bare `location` attribute fallback for parity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements the
turbo_visitaction, which navigates viaTurbo.visit(location, { action, frame }).turbo_visittosrc/actions/turbo.tsand registered it.locationattribute (default/),turbo-actionattribute (defaultadvance),turbo-frameattribute (mapped toTurbo.visit'sframeoption, mirroringredirect_to).test/turbo/turbo_visit.test.js—locationfallbacks (including the bare attribute),turbo-actionvalues, andturbo-frame.turbo_visit(location, turbo_action = "advance", turbo_frame = nil, **attributes).Closes #18
🤖 Generated with Claude Code