morphodict
morphodict copied to clipboard
On search page, push to history when user stops typing
Makes the behaviour of the back button a bit more intuitive. Basically, when a user has finished typing a query, views some results, then types a different query, they expect that to be two different search results. However, if you don't navigate away from the search results, it all looks like one state in history. So there should be some heuristic that states, "user is looking at the results and no longer typing".
I +1'ed this because I just did this same thing. I wanted to go back to my previous search, and it navigated me away from Itwêwina instead.
Fun fact! The browser is free to ignore history.pushState() calls:
the user agent might disallow calls to these methods that are invoked on a timer, or from event listeners that are not triggered in response to a clear user action, or that are invoked in rapid succession
[source]
Cypress necessarily calls this within a timer, making testing this next to impossible! 😭
Issues I encountered trying to solve this:
- Cypress works poorly with the history API
cy.go('back')dead-ass navigates OUT OF THE TESTS. There's no failure; it just leaves the test runner entirel 😱history.pushState()will actually affect history in Chromium if inside a non-user callback. Which is what happens in the unit test
- so we should unit test?
- use Cypress with Karma: I cannot find anything that claims to combine the two. Maybe for good reason
- unit test with Cypress: but then the raw files need to be importable by Cypress...
Anyway, I wasted my entire morning on this, so I'm gonna go for a hot (hopefully I don't melt 🥵 ) and come back to this later 😅