diff --git a/app/components/Package/Versions.vue b/app/components/Package/Versions.vue index f915eb759..3baab617c 100644 --- a/app/components/Package/Versions.vue +++ b/app/components/Package/Versions.vue @@ -211,12 +211,16 @@ const visibleTagRows = computed(() => { ) : rowsMaybeFilteredForDeprecation const first = rows.slice(0, MAX_VISIBLE_TAGS) - const latestTagRow = rows.find(row => row.tag === 'latest') - // Ensure 'latest' tag is always included (at the end) if not already present - if (latestTagRow && !first.includes(latestTagRow)) { - first.pop() - first.push(latestTagRow) + + // When no filter is active, ensure 'latest' is always shown (even if not fully loaded) + if (!isFilterActive.value) { + const latestTagRow = rows.find(row => row.tag === 'latest') + if (latestTagRow && !first.includes(latestTagRow)) { + first.pop() + first.push(latestTagRow) + } } + return first }) diff --git a/test/nuxt/components/Package/Versions.spec.ts b/test/nuxt/components/Package/Versions.spec.ts index afb183acf..03d3e2db6 100644 --- a/test/nuxt/components/Package/Versions.spec.ts +++ b/test/nuxt/components/Package/Versions.spec.ts @@ -1281,6 +1281,21 @@ describe('PackageVersions', () => { expect(text).not.toContain('0.5.0') }) }) + + it('does not show latest tag when it does not match the filter', async () => { + const component = await mountSuspended(PackageVersions, { props: multiVersionProps }) + + const input = component.find('input[type="text"]') + await input.setValue('^1.0.0 <2.0.0') + + const versionLinks = component.findAll('a').filter(isVersionLink) + const versions = versionLinks.map(l => l.text()) + + // 3.0.0 is latest but does NOT match the filter + expect(versions).not.toContain('3.0.0') + // 1.0.0 does match + expect(versions).toContain('1.0.0') + }) }) describe('error handling', () => {