swup / fragment-plugin

A swup plugin for dynamically replacing containers based on rules 🧩
https://swup-fragment-plugin.netlify.app
MIT License
15 stars 1 forks source link

Think through what should happen if all fragments in a visit already match the new URL #80

Open hirasso opened 3 months ago

hirasso commented 3 months ago

Describe the problem 🧐

If all fragments in a visit already match visit.to.url, currently the matching fragment visit will simply be ignored, falling back to swups default containers for that visit.

That is not what would be expected. That kind of situation is basically like a link to the current page, even though the visit.from.url is not equal to visit.to.url.

Describe the propsed solution 😎

I've done a bit of research in #79 and then decided to first start with an issue.

I'm unsure about the ideal solution for the scenario described above. Maybe the behavior could be aligned with whatever is defined in swup.options.linkToSelf:

As mentioned above, I'm not absolutely sure about the perfect solution here. Happy to talk it all through together.

Alternatives considered πŸ€”

Add a hook and always remove the fragment URL from the fragment element:

/** allow details to always be replaced */
swup.hooks.on("visit:end", () => {
  const detail = $<FragmentElement>("#detail")!;
  detail.__swupFragment!.url = "";
});

How important is this feature to you? 🧭

Would make my life a lot easier

Checked all these? πŸ“š