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
New global option: resolvePath
#512
Conversation
time the URL is being changed
to help with understanding
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
Nice! Will check it out this week. |
One thought beforehand: returning |
`null`, `false`, `undefined` or `''` will all result in a warning now to help with the implementation of this option.
I would actually prefer to be quite strict here, a warning will hopefully help people with the implementation. The function should always return a non-empty string. I actually also thought about validating if the resolved path is actually a path and not a full URL, as well. |
Could you also have a look at the tests? They are passing locally, I don't understand what's going on in the CI 🙏 |
Looks like we reached the monthly limit for the free CircleCI plan, it won't show the test run :( |
I think it might be the complex transitions test, the duration was a bit outside the expected range one time I let it run locally. |
You could try increasing the expected range — it's a constant somewhere at the top of |
Great, that worked! 🎺 |
@daun do you have any reservations against merging this? |
@hirasso Only that I've been super busy and haven't had the time to thoroughly test this. I hope I can give it a spin later this week or on the weekend. |
Sorry for the delay in checking this out. Looks good! It's something we should definitely have in the codebase. One question about the scope: does the linked example always return the same HTML, regardless of the |
Yes, each The cache must use If you need further clarification, I would be happy to walk you through it in a call – otherwise I would proceed and merge this. Documentation can be a separate PR. |
Actually, thinking about it: The concept is actually quite similar to canonical URLs:
So maybe renaming the option to |
Let's jump on a quick call whenever convenient! I agree with the reasoning but would just like to get your input on how I have been solving those filter ui situations. Ideally this PR would cover both ways of tackling it. I'd stick with the current naming. Calling it canonical would somewhat imply being tied to a hypothetically present meta tag whereas resolve is more neutral. |
I see... Do you also prefer |
I think I prefer How strong is your aversion to using |
Not strong at all. Just wanted to make sure we are naming it correctly. Let's stay with resolve, then! 👏 |
Replaces #508
Adds a new global option to swup, that allows to run a callback for how swup should resolve a path.
What is the problem?
Right now, to be able to leave and re-enter control over the browser URL/state by swup, three steps are necessary:
skipPopStateHandling
with custom logiclinkSelector
,stopPropagation()
during the capture phase,...)While this kind of behavior is already possible to achieve with the currently available swup API, it adds a lot of boilerplate to each new site that wants to have this. Also, the current cache implementation is less than ideal for that kind of scenario right now. It will either fill itself up with unnecessary duplicates of the same page or have cache misses for pages that were previously already loaded from the server.
Proposed solution
All three of the above topics basically boil down to always the same question: Should various paths actually be resolved to just one by swup?
popState
: Is the resolved version of the new browser URL the same as the previous one? > ignoreclickLink
: Is the resolved href of the link the same as the current browser URL? > ignoreDemo & Test Site
I have set-up a test site here: https://test.rassohilber.com/swup-resolve-path/test/
On that site, the whole filter logic is done by a custom component that doesn't want swup to interfere. It does everything from updating the URL to rendering the state. Navigation away from the list to one of the character detail pages or to the "about"-page and back again is being handled by swup again. To make it more obvious that there is no page load between filters, I added a staggered animation to the items that only runs if the page is being fully rendered (initially and by swup).
Code Example
Checks