Skip to content

Encode Visit Action into Turbo-Action: header#694

Open
seanpdoyle wants to merge 1 commit intohotwired:mainfrom
seanpdoyle:visit-action-header
Open

Encode Visit Action into Turbo-Action: header#694
seanpdoyle wants to merge 1 commit intohotwired:mainfrom
seanpdoyle:visit-action-header

Conversation

@seanpdoyle
Copy link
Copy Markdown
Contributor

When initiating a Visit from an <a data-turbo-action="..."> element,
encode the Action value into the request's Turbo-Action: header.

Similarly, when submitting a <form data-turbo-action="...">, encode
the value into the header.

If a <turbo-frame> is navigated with an Action, encode the action
along with the Turbo-Frame: header.

@seanpdoyle seanpdoyle force-pushed the visit-action-header branch 2 times, most recently from 18eeb72 to 836a00a Compare September 14, 2022 19:33
@seanpdoyle seanpdoyle force-pushed the visit-action-header branch 3 times, most recently from f9ae4d2 to 41d489f Compare November 27, 2022 19:39
@seanpdoyle seanpdoyle force-pushed the visit-action-header branch 2 times, most recently from 5fa4991 to b2e2b09 Compare December 31, 2022 23:05
@seanpdoyle seanpdoyle force-pushed the visit-action-header branch from 99814da to 969e56a Compare July 21, 2023 15:31
When initiating a `Visit` from an `<a data-turbo-action="...">` element,
encode the Action value into the request's `Turbo-Action:` header.

Similarly, when submitting a `<form data-turbo-action="...">`, encode
the value into the header.

If a `<turbo-frame>` is navigated with an Action, encode the action
along with the `Turbo-Frame:` header.
@jarenas9539
Copy link
Copy Markdown

jarenas9539 commented Feb 24, 2024

This is exactly what I was trying to achieve here hotwired/turbo-rails#594. I was barking to the wrong tree 😅.
I stepped into a use case recently where this Turbo-Action header on the controller could be very helpful. Let me draw the context with my case:

  • Devise has a helper called store_location_for used on controllers to keep track of not logged users navigation and redirect them to the last location after a login/signup.
  • Now suppose we have a page with two turbo-frames, one that is updated by a button with data-turbo-action="advance" and a lazy loaded turbo modal.
  • If user visits the page, clicks the button and open the modal, 3 requests are triggered, I'll call them A, B and C respectively. - Then the user use our login button, log himself and the situation happens.
    • If we register all the request paths on controller, the user is redirected to path C, an HTML just with a turbo-frame with the modal info
    • If we avoid to register all turbo-frames using the turbo_frame_request? helper, the user is redirected to A. But B is a valid page and when he clicked the button from A a "navigation" occurred
    • In this case, expected result is being redirected to B. So we want to register A and B requests, and ignore C. But how could we identify if a frame request is causing a "navigation" or not.

On this last point is where Turbo-Action header could be very helpful as we could easily write a helper checking if a turbo frame request triggers an URL update ("advance" and "restore"), using this we could easily select which paths to store and which paths to ignore. Is this one planned at short term?
When this one gets merged the helper on FrameRequest from turbo-rails could be a good addition.

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