By adding a data attribute to a normal link like the below:
<a href="/posts" data-sg-visit>
Superglue makes a SPA visit from one page to another without reloading the page. This is achieved by grabbing the next page's props at /posts.json, and passing it into the next page's component while pushing history state. data-sg-visit is powered by the visit function, which you can override when you first generate a new superglue app.
Superglue adds a handler to watch out for DOM elements with data-sg-* attributes. These handlers are created here and you may spot that data-sg-visit has a companion handler called data-sg-placeholder. This is documented here.
Issue
data-sg-visit pushes history upon a successful visit using a link/ form. What I'd like to add is a companion data attribute, in the same vien as data-sg-placeholder, that would replace history instead.
The visit function doesn't quite have this ability yet. Instead it passes a suggestedAction to your application_visithere. And that suggested action is determined here.
context
Superglue embraces UJS helpers.
By adding a data attribute to a normal link like the below:
Superglue makes a SPA visit from one page to another without reloading the page. This is achieved by grabbing the next page's props at
/posts.json
, and passing it into the next page's component while pushing history state.data-sg-visit
is powered by the visit function, which you can override when you first generate a new superglue app.Superglue adds a handler to watch out for DOM elements with data-sg-* attributes. These handlers are created here and you may spot that
data-sg-visit
has a companion handler calleddata-sg-placeholder
. This is documented here.Issue
data-sg-visit
pushes history upon a successful visit using a link/ form. What I'd like to add is a companion data attribute, in the same vien asdata-sg-placeholder
, that would replace history instead.The
visit
function doesn't quite have this ability yet. Instead it passes asuggestedAction
to yourapplication_visit
here. And that suggested action is determined here.So to create this functionality we need to allow the visit function to accept a
suggestedAction
to override the smart defaults https://github.com/thoughtbot/superglue/blob/fd3f027868f9db536db5ebc8b24c02a2f7c1fc62/superglue/lib/action_creators/requests.js#L208So that it'll be eventually passed to
https://github.com/thoughtbot/superglue/blob/fd3f027868f9db536db5ebc8b24c02a2f7c1fc62/superglue_rails/lib/install/templates/web/application_visit.js#L24
Then finally, add the data attribute handler
data-sg-replace
to https://github.com/thoughtbot/superglue/blob/main/superglue/lib/utils/ujs.js#L90I'm open to naming suggestions to the UJS attribute, variables, etc.