@@ -28,7 +28,6 @@ const fromVersion = computed(() => versionRange.value?.from ?? '')
2828const toVersion = computed (() => versionRange .value ?.to ?? ' ' )
2929
3030const router = useRouter ()
31- const initializedFromQuery = ref (false )
3231const { data : pkg } = usePackage (packageName )
3332
3433const { data : compare, status : compareStatus } = useFetch <CompareResponse >(
@@ -39,7 +38,7 @@ const { data: compare, status: compareStatus } = useFetch<CompareResponse>(
3938 },
4039)
4140
42- const selectedFile = ref <FileChange | null >(null )
41+ const manualSelection = ref <FileChange | null >(null )
4342const fileFilter = ref <' all' | ' added' | ' removed' | ' modified' >(' all' )
4443const mobileDrawerOpen = ref (false )
4544
@@ -52,17 +51,19 @@ const allChanges = computed(() => {
5251 ].sort ((a , b ) => a .path .localeCompare (b .path ))
5352})
5453
55- const selectedFromQuery = computed (() => {
56- const filePath = route .query .file
57- if (! filePath || ! compare .value ) return null
58- return allChanges .value .find (f => f .path === filePath ) ?? null
59- })
60-
61- // Sync selection with ?file= query for shareable links (SSR + client)
62- watchEffect (() => {
63- if (initializedFromQuery .value || ! selectedFromQuery .value ) return
64- selectedFile .value = selectedFromQuery .value
65- initializedFromQuery .value = true
54+ // Derive selected file: manual selection takes priority, then ?file= query param.
55+ // Using a computed ensures the query-param file is resolved during SSR without
56+ // needing a watcher (which may not re-run before SSR rendering completes).
57+ const selectedFile = computed <FileChange | null >({
58+ get : () => {
59+ if (manualSelection .value ) return manualSelection .value
60+ const filePath = route .query .file
61+ if (! filePath || ! compare .value ) return null
62+ return allChanges .value .find (f => f .path === filePath ) ?? null
63+ },
64+ set : file => {
65+ manualSelection .value = file
66+ },
6667})
6768
6869if (import .meta .client ) {
0 commit comments