You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
So to create this functionality we need to allow the visit function to accept a suggestedAction to override the smart defaults
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 defaultssuperglue/superglue/lib/action_creators/requests.js
Line 208 in fd3f027
So that it'll be eventually passed to
superglue/superglue_rails/lib/install/templates/web/application_visit.js
Line 24 in fd3f027
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.
The text was updated successfully, but these errors were encountered: