Skip to content

Commit 14912af

Browse files
committed
fix: address CodeRabbit review feedback
- Hide dependencies menu item when install size data is unavailable - Guard against non-OK fetch responses before creating blob - Use Vue 3.4 same-name shorthand for :size binding - Remove console.error in favor of silent fallback - Fix missing test closure in a11y spec
1 parent 7a6e29e commit 14912af

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

app/components/Package/DownloadButton.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ const dropdownPosition = shallowRef<{ top: number; right: number } | null>(null)
2222
2323
const { t } = useI18n()
2424
const menuId = useId()
25-
const menuItems = computed(() => [
26-
{ id: 'package', label: t('package.download.package'), icon: 'i-lucide:package' },
27-
{ id: 'dependencies', label: t('package.download.dependencies'), icon: 'i-lucide:list-tree' },
28-
])
25+
const menuItems = computed(() => {
26+
const items = [{ id: 'package', label: t('package.download.package'), icon: 'i-lucide:package' }]
27+
if (props.installSize) {
28+
items.push({
29+
id: 'dependencies',
30+
label: t('package.download.dependencies'),
31+
icon: 'i-lucide:list-tree',
32+
})
33+
}
34+
return items
35+
})
2936
3037
function getDropdownStyle(): Record<string, string> {
3138
if (!dropdownPosition.value) return {}
@@ -108,6 +115,9 @@ async function downloadPackage() {
108115
109116
try {
110117
const response = await fetch(tarballUrl)
118+
if (!response.ok) {
119+
throw new Error(`Failed to fetch tarball (${response.status})`)
120+
}
111121
const blob = await response.blob()
112122
const url = URL.createObjectURL(blob)
113123
const link = document.createElement('a')
@@ -117,8 +127,7 @@ async function downloadPackage() {
117127
link.click()
118128
document.body.removeChild(link)
119129
URL.revokeObjectURL(url)
120-
} catch (error) {
121-
console.error('Failed to download package:', error)
130+
} catch {
122131
// Fallback to direct link for non-CORS or other issues, though download attribute may be ignored
123132
const link = document.createElement('a')
124133
link.href = tarballUrl
@@ -183,7 +192,7 @@ defineOptions({
183192
v-bind="$attrs"
184193
type="button"
185194
:variant="size === 'small' ? 'subtle' : 'secondary'"
186-
:size="size"
195+
:size
187196
classicon="i-lucide:download"
188197
:aria-expanded="isOpen"
189198
aria-haspopup="menu"

test/nuxt/a11y.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,6 +3332,12 @@ describe('component accessibility audits', () => {
33323332
hunks: [],
33333333
type: 'modify',
33343334
fileName: 'empty.ts',
3335+
},
3336+
})
3337+
const results = await runAxe(component)
3338+
expect(results.violations).toEqual([])
3339+
})
3340+
})
33353341

33363342
describe('DiffSidebarPanel', () => {
33373343
const mockCompare = {

0 commit comments

Comments
 (0)