Skip to content

Commit ce8f761

Browse files
committed
fix: tackle hydration issue
1 parent ac9f388 commit ce8f761

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

app/pages/diff/[[org]]/[packageName]/v/[versionRange].vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const fromVersion = computed(() => versionRange.value?.from ?? '')
2828
const toVersion = computed(() => versionRange.value?.to ?? '')
2929
3030
const router = useRouter()
31-
const initializedFromQuery = ref(false)
3231
const { data: pkg } = usePackage(packageName)
3332
3433
const { 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)
4342
const fileFilter = ref<'all' | 'added' | 'removed' | 'modified'>('all')
4443
const 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
6869
if (import.meta.client) {

0 commit comments

Comments
 (0)