Tick a filter at once, not after the URL has changed (#68) #92
+32
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #68.
The filter checkboxes did not look ticked right after a click. On the VM, right after clicking «Rødvin» the URL was already
?type=rodvin, but the checkbox was not ticked. It was ticked about 18 ms later.Why: React Router changes the URL in a transition. The checkbox is controlled by the URL, so until the transition commits, React puts it back the way it was. Playwright checks at once, so
check()failed on desktop and mobile. A screen reader does the same, and announces «ikke avkrysset» when the user presses Space. That is probably why a peer reviewer wrote that the filters could not be used with the keyboard.Fix:
SearchPagekeeps the choice in local state, which React applies before it restores a controlled input, so the checkbox and the sort select change at once. The queries still follow the URL, and the local state is reset every time the URL changes (back button, «Nullstill filtre», removing a filter), so the URL stays the truth.useOptimisticwas tried first, but it did not show the choice soon enough to beat the restore.Tested:
npm run checkpasses, and all e2e tests pass (80 passed, 2 skipped, which are the mobile-only tests in the desktop project). The test that failed in #68 now passes on desktop and mobile. Also tried by hand on the search page.🤖 Generated with Claude Code