Skip to content

Commit 083e17f

Browse files
committed
fix: compute license changes in page
If we compute the license change in the warning component, it is possible the fetch resolves _after_ SSR completes it seems. So this means the result is null and no notice is shown (via SSR). When you later navigate to a version, the client does an actual fetch and the notice is now shown. To fix this, I've moved the license change call to the page which is how all other composables in this page work. The license warning component then just consumes the change data.
1 parent e1a28da commit 083e17f

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

app/components/LicenseChangeWarning.vue

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
<script setup lang="ts">
2-
import { useLicenseChanges } from '~/composables/useLicenseChanges'
2+
import type { LicenseChangeResponse } from '~/composables/useLicenseChanges'
33
44
const props = defineProps<{
5-
license?: string
6-
packageName?: string
7-
resolvedVersion: string | null | undefined
5+
change: LicenseChangeResponse['change']
86
}>()
9-
10-
const { data: licenseData } = useLicenseChanges(
11-
() => props.packageName,
12-
() => props.resolvedVersion,
13-
)
14-
15-
const licenseChangeRecord = computed(() => licenseData?.value?.change ?? null)
167
</script>
178

189
<template>
1910
<div
20-
v-if="licenseChangeRecord"
11+
v-if="props.change"
2112
class="border border-amber-600/40 bg-amber-500/10 rounded-lg mt-1 gap-x-1 py-2 px-3"
2213
:aria-label="$t('package.versions.license_change_help')"
2314
>
@@ -32,8 +23,8 @@ const licenseChangeRecord = computed(() => licenseData?.value?.change ?? null)
3223
<p class="text-md text-amber-800 dark:text-amber-400 mt-1">
3324
{{
3425
$t('package.versions.license_change_record', {
35-
from: licenseChangeRecord?.from,
36-
to: licenseChangeRecord?.to,
26+
from: props.change?.from,
27+
to: props.change?.to,
3728
})
3829
}}
3930
</p>

app/composables/useLicenseChanges.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { MaybeRefOrGetter } from 'vue'
22
import { toValue } from 'vue'
3-
interface LicenseChangeResponse {
3+
4+
export interface LicenseChangeResponse {
45
change: { from: string; to: string } | null
56
}
67

app/pages/package/[[org]]/[name].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ const {
199199
error,
200200
} = usePackage(packageName, () => resolvedVersion.value ?? requestedVersion.value)
201201
202+
const { data: licenseChangeData } = useLicenseChanges(packageName, resolvedVersion)
202203
const { diff: sizeDiff } = useInstallSizeDiff(packageName, resolvedVersion, pkg, installSize)
203204
const { versions: commandPaletteVersions, ensureLoaded: ensureCommandPaletteVersionsLoaded } =
204205
useCommandPalettePackageVersions(packageName)
@@ -906,7 +907,7 @@ const showSkeleton = shallowRef(false)
906907

907908
<div class="space-y-6" :class="$style.areaVulns">
908909
<!-- license change warning -->
909-
<LicenseChangeWarning :packageName="pkg.name" :resolvedVersion="resolvedVersion" />
910+
<LicenseChangeWarning :change="licenseChangeData?.change ?? null" />
910911
<!-- Bad package warning -->
911912
<PackageReplacement v-if="moduleReplacement" :replacement="moduleReplacement" />
912913
<!-- Size / dependency increase notice -->

test/nuxt/a11y.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ describe('component accessibility audits', () => {
391391
it('should have no accessibility violations', async () => {
392392
const component = await mountSuspended(LicenseChangeWarning, {
393393
props: {
394-
packageName: 'vue',
395-
resolvedVersion: '3.4.0',
394+
change: { from: 'MIT', to: 'GPL-3.0' },
396395
},
397396
global: {
398397
mocks: { $t: (key: string) => key },

0 commit comments

Comments
 (0)