Skip to content

Commit 5afbf81

Browse files
committed
chore: fix test:nuxt
1 parent 60fdf4a commit 5afbf81

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

app/composables/usePackageComparison.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
7474
const compactNumberFormatter = useCompactNumberFormatter()
7575
const bytesFormatter = useBytesFormatter()
7676
const packages = computed(() => toValue(packageNames))
77-
78-
const ready = shallowRef(false)
77+
const nuxt = useNuxtApp()
7978

8079
// Cache of fetched data by package name (source of truth)
8180
const cache = shallowRef(new Map<string, PackageComparisonData>())
8281

8382
// Derived array in current package order
8483
const packagesData = computed(
85-
() => ready.value && packages.value.map(name => cache.value.get(name) ?? null),
84+
() =>
85+
import.meta.client &&
86+
!nuxt.isHydrating &&
87+
packages.value.map(name => cache.value.get(name) ?? null),
8688
)
8789

8890
const status = shallowRef<'idle' | 'pending' | 'success' | 'error'>('idle')
@@ -253,22 +255,21 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
253255

254256
// Watch for package changes and refetch (client-side only)
255257
if (import.meta.client) {
256-
useNuxtApp().hook('app:suspense:resolve', () => {
257-
ready.value = true
258-
watch(
259-
packages,
260-
newPackages => {
258+
watch(
259+
() => [nuxt.isHydrating, packages.value] as const,
260+
([isHydrating, newPackages]) => {
261+
if (!isHydrating) {
261262
fetchPackages(newPackages)
262-
},
263-
{ immediate: true },
264-
)
265-
})
263+
}
264+
},
265+
{ immediate: true },
266+
)
266267
}
267268

268269
// Compute values for each facet
269270
function getFacetValues(facet: ComparisonFacet): (FacetValue | null)[] {
270271
// If not ready or no data, return array of nulls to render skeletons
271-
if (!ready.value || !packagesData.value || packagesData.value.length === 0) {
272+
if (!packagesData.value || packagesData.value.length === 0) {
272273
return Array.from({ length: packages.value.length }, () => null)
273274
}
274275

test/nuxt/components/compare/FacetRow.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('FacetRow', () => {
4545
})
4646

4747
describe('value rendering', () => {
48-
it('renders null values as dash', async () => {
48+
it('renders null values as skeleton', async () => {
4949
const component = await mountSuspended(FacetRow, {
5050
props: {
5151
...baseProps,
@@ -54,7 +54,8 @@ describe('FacetRow', () => {
5454
})
5555
const cells = component.findAll('.comparison-cell')
5656
expect(cells.length).toBe(2)
57-
expect(component.text()).toContain('-')
57+
// Should render SkeletonInline component (check for skeleton class)
58+
expect(component.findAll('.animate-skeleton-pulse').length).toBe(2)
5859
})
5960

6061
it('renders facet values', async () => {

0 commit comments

Comments
 (0)