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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Allow to customize the cache behavior in form visits #72

Closed
4 tasks done
hirasso opened this issue Apr 12, 2024 · 0 comments
Closed
4 tasks done

Comments

@hirasso
Copy link
Member

hirasso commented Apr 12, 2024

Describe the problem 馃

Currently, forms-plugin will always delete the cache of the target page before navigating towards it:

forms-plugin/src/index.ts

Lines 178 to 179 in 43d235c

this.swup.cache.delete(action);
this.swup.navigate(action + hash, params, { el, event });

This makes sense for most cases (search, contact forms, ...), but in other cases the cache might actually be useful. One example where I ran into this problem is a list that can be filtered by submitting a form:

https://example.com/users
https://example.com/users?filter=foo
https://example.com/users?filter=bar&sort=baz

Describe the propsed solution 馃槑

I'd like to make the cache controllable via the visit object. To reproduce the current behavior, this instantiation would make sense:

- this.swup.cache.delete(action);
- this.swup.navigate(action + hash, params, { el, event });
+const cache = {
+	read: false,
+	write: true
+};
+this.swup.navigate(action + hash, { ...params, cache }, { el, event });

That way, the consumer could decide if the request should make use of the cache or not (default: no cache):

swup.hooks.on("visit:start", (visit) => {
  if (visit.trigger.el?.matches('.my-filter-form')) {
    visit.cache.read = true;
  }
});

...or simply this if all requests should be cached:

swup.hooks.on("visit:start", (visit) => {
  visit.cache.read = true;
});

Alternatives considered 馃

Not really an alternative that comes to mind. An attribute just for this would be pretty convoluted.

How important is this feature to you? 馃Л

Would make my life a lot easier

Checked all these? 馃摎

@hirasso hirasso closed this as completed Apr 13, 2024
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