refactor(ui): fetch results on submit instead of on type#1107
refactor(ui): fetch results on submit instead of on type#1107MatteoGabriele wants to merge 14 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
…riele/npmx.dev into fix/search-reliability
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThis pull request refactors the search functionality by consolidating and relocating the search component logic. A new generic SearchBox component is introduced to replace the Header-specific SearchBox, which is removed. The AppHeader component is updated to handle search query synchronisation with the URL via a debounced handler and route watcher. The home page search submission is simplified. Test files are updated to reference the new SearchBox component and unified search input selector. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
app/components/SearchBox.vue (1)
77-93: Remove inlinefocus-visibleutility from the<button>element.The button at line 79 uses
focus-visible:outline-accent/70, but project convention is to rely on the global rule inmain.cssfor buttons and selects. Based on learnings: "individual buttons or selects in Vue components should not rely on inline focus-visible utility classes likefocus-visible:outline-accent/70."♻️ Proposed fix
<button type="submit" - class="absolute hidden `@xs`:block group inset-ie-2.5 font-mono text-sm transition-[background-color,transform] duration-200 active:scale-95 focus-visible:outline-accent/70" + class="absolute hidden `@xs`:block group inset-ie-2.5 font-mono text-sm transition-[background-color,transform] duration-200 active:scale-95"app/components/AppHeader.vue (1)
33-42: Consider extracting duplicated search-navigation logic into a composable.
handleSearchSubmitis identical in bothindex.vueandAppHeader.vue. A shared composable (e.g.,useSearchNavigation) would reduce duplication and ensure consistent behaviour if the navigation logic changes.
|
would you check the e2e tests? they test a lot of functionality that has changed, so I expect they need to be updated.... |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
app/components/SearchBox.vue (1)
74-90: Remove inlinefocus-visibleutility from the submit button.The submit button applies
focus-visible:outline-accent/70as an inline utility class. The project applies focus-visible styling forbuttonandselectelements globally viamain.css. Per-element inline utilities on buttons should be avoided to keep styling consistent and maintainable.Proposed fix
<button type="submit" - class="absolute hidden `@xs`:block group inset-ie-2.5 font-mono text-sm transition-[background-color,transform] duration-200 active:scale-95 focus-visible:outline-accent/70" + class="absolute hidden `@xs`:block group inset-ie-2.5 font-mono text-sm transition-[background-color,transform] duration-200 active:scale-95"Based on learnings: "In the npmx.dev project, focus-visible styling for buttons and selects is applied globally via main.css… individual buttons or selects in Vue components should not rely on inline focus-visible utility classes like focus-visible:outline-accent/70."
ghostdevv
left a comment
There was a problem hiding this comment.
I noticed that when I search for something that has an exact match, I press enter to trigger the search I see the results for half a second then I get taken to the package because of the exact match
Changes the update to occur on submit rather than on typing. This reduces requests to the registry API, minimizes router updates to the input value, which can cause issues like missing letters, and prevents empty responses when results are available.
it would be nice if it was throttled (as you're typing it searches every N seconds), but I understand that it may be tricky with the whole navigation between pages and such.
app/components/AppHeader.vue
Outdated
| await navigateTo({ | ||
| name: 'search', | ||
| query: { q: searchQuery.value }, | ||
| }) |
There was a problem hiding this comment.
what's the difference in nuxt between the router.push that was happening before, and this?
There was a problem hiding this comment.
In this case, I think either option would work.
Previously, this component had no route handling, so I copy-pasted the function from the homepage, as they serve the same purpose. I didn't check whether it was navigateTo or router.push, since they essentially perform the same action. I believe navigateTo is a helper function that can also be used on the server side.
|
@ghostdevv I see that "exact" behaviour as well now. |
|
@ghostdevv I've removed the "Enter to exact" functionality since we now use Enter to actually search. What do you think? |
|
I just wonder if we can't solve the search issue without sacrificing on enter to exact or the results updating as you type... like the registry requests is annoying but can be fine tuned/cached I think and is worth it for the user experience, and the other issues should be solvable 🤔 wdyt?
just as an alternative to debounce which has a nicer UX - but it only matters if we can fix the underlying problems |
|
@ghostdevv I have re-implemented an update-on-type feature, but instead of using a watcher, I am now debouncing the search input update so it is not linked to the route update. It seems to be working better, avoiding the weird update loop we had before. I also re-enabled the enter key functionality. Let me know what you think of this version. PS: The index still uses the Enter key to prevent accidental page change while typing, which could cause loss of focus or characters, or a disruptive experience. |
Uh oh!
There was an error while loading. Please reload this page.