Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a data-sg-replace companion to data-sg-visit to replace history instead of push #62

Open
jho406 opened this issue May 29, 2024 · 0 comments

Comments

@jho406
Copy link
Collaborator

jho406 commented May 29, 2024

context

Superglue embraces UJS helpers.

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_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

meta.suggestedAction = 'push'

So that it'll be eventually passed to

ref.current.navigateTo(meta.pageKey, {

Then finally, add the data attribute handler data-sg-replace to https://github.com/thoughtbot/superglue/blob/main/superglue/lib/utils/ujs.js#L90

I'm open to naming suggestions to the UJS attribute, variables, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant