Skip to content

Commit 8a91f8e

Browse files
committed
Tighten Nuxt example navigation and search race
Move the search debounce's `latestSearchRequest` increment to the top of the timeout callback so clearing the input invalidates any in-flight `/api/search` response. The previous order let a slow prior fetch overwrite the just-cleared `searchResult`. Convert the post detail page's author link from a raw anchor to `<NuxtLink>` so navigating to the author profile uses Nuxt's client-side router instead of triggering a full page reload, in line with the back-link conversion already applied to the page. #676 Assisted-by: Claude Code:claude-opus-4-7
1 parent a888000 commit 8a91f8e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

examples/nuxt/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ let latestSearchRequest = 0;
184184
function onSearchInput() {
185185
if (searchTimeout) clearTimeout(searchTimeout);
186186
searchTimeout = setTimeout(async () => {
187+
const requestId = ++latestSearchRequest;
187188
if (!searchQuery.value.trim()) {
188189
searchResult.value = null;
189190
return;
190191
}
191-
const requestId = ++latestSearchRequest;
192192
const res = await $fetch<{ result: typeof searchResult.value }>(
193193
`/api/search?q=${encodeURIComponent(searchQuery.value)}`,
194194
);

examples/nuxt/pages/users/[identifier]/posts/[id].vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<div v-if="data" class="post-detail-container">
33
<NuxtLink class="back-link" to="/">&larr; Back to home</NuxtLink>
44
<article class="post-detail-card">
5-
<a
5+
<NuxtLink
66
class="post-detail-author"
7-
:href="`/users/${data.identifier}`"
7+
:to="`/users/${data.identifier}`"
88
>
99
<img
1010
:src="data.author.icon ?? '/demo-profile.png'"
@@ -24,7 +24,7 @@
2424
{{ formatDate(data.published) }}
2525
</time>
2626
</div>
27-
</a>
27+
</NuxtLink>
2828
<div class="post-detail-content">
2929
<p>{{ data.content }}</p>
3030
</div>

0 commit comments

Comments
 (0)