Skip to content

Commit 9fe7204

Browse files
committed
fix(ui): respect semver filter when showing latest tag
The 'latest' tag was unconditionally added to visible results even when it didn't match the active semver filter. This caused versions like 7.6.0 to appear when filtering by ranges like '^7.5 <7.6'. Remove the special case handling for the 'latest' tag and let it flow naturally through the filtering logic. This makes the behavior more predictable and fixes the bug where non-matching versions were displayed.
1 parent 5324b96 commit 9fe7204

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

app/components/Package/Versions.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,7 @@ const visibleTagRows = computed(() => {
210210
getTagVersions(row.tag).some(v => filteredVersionSet.value.has(v.version)),
211211
)
212212
: rowsMaybeFilteredForDeprecation
213-
const first = rows.slice(0, MAX_VISIBLE_TAGS)
214-
const latestTagRow = rows.find(row => row.tag === 'latest')
215-
// Ensure 'latest' tag is always included (at the end) if not already present
216-
if (latestTagRow && !first.includes(latestTagRow)) {
217-
first.pop()
218-
first.push(latestTagRow)
219-
}
220-
return first
213+
return rows.slice(0, MAX_VISIBLE_TAGS)
221214
})
222215
223216
// Hidden tag rows (all other tags) - shown in "Other versions"

test/nuxt/components/Package/Versions.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,22 @@ describe('PackageVersions', () => {
12811281
expect(text).not.toContain('0.5.0')
12821282
})
12831283
})
1284+
1285+
it('does not show latest tag when it does not match the filter', async () => {
1286+
// This tests the fix for issue where ^7.5 <7.6 was showing 7.6.0 (which is tagged latest)
1287+
const component = await mountSuspended(PackageVersions, { props: multiVersionProps })
1288+
1289+
const input = component.find('input[type="text"]')
1290+
// Filter to ^1.0.0 which should NOT match 3.0.0 (the latest version)
1291+
await input.setValue('^1.0.0 <2.0.0')
1292+
1293+
// 3.0.0 (latest) should NOT appear because it doesn't match the filter
1294+
const versionLinks = component.findAll('a').filter(isVersionLink)
1295+
const versions = versionLinks.map(l => l.text())
1296+
expect(versions).not.toContain('3.0.0')
1297+
// But 1.0.0 should appear because it matches the filter
1298+
expect(versions).toContain('1.0.0')
1299+
})
12841300
})
12851301

12861302
describe('error handling', () => {

0 commit comments

Comments
 (0)