Skip to content

Commit 5cdbd4b

Browse files
committed
fix: resolve hash-based component triggering issues
- Fix useHashChecker to read actual hash value instead of stale computed value - Remove LoginAlertDialog from ForumLocalNav as it's now in Layout - Ensure hash-based triggers work immediately for both login alerts and forum forms - Clean up debug logging after successful troubleshooting
1 parent a088e21 commit 5cdbd4b

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

.vitepress/theme/components/ui/sonner/Sonner.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts" setup>
22
import type { ToasterProps } from 'vue-sonner'
33
import { Toaster as Sonner } from 'vue-sonner'
4+
import 'vue-sonner/style.css'
45
56
const props = defineProps<ToasterProps>()
67
</script>

.vitepress/theme/hooks/useHashChecker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ export function useHashChecker(
3434
let matchedHash = null
3535

3636
const checkHash = () => {
37+
// 直接读取当前hash,不依赖computed
38+
const actualCurrentHash = import.meta.env.SSR ? '' : window.location.hash.slice(1)
39+
3740
if (isArray(targetHash)) {
38-
isMatch.value = targetHash.includes(currentHash.value)
41+
isMatch.value = targetHash.includes(actualCurrentHash)
3942
}
4043
else {
41-
isMatch.value = currentHash.value === targetHash
44+
isMatch.value = actualCurrentHash === targetHash
4245
}
4346

4447
if (!isMatch.value)
4548
return
4649

47-
matchedHash = currentHash.value
50+
matchedHash = actualCurrentHash
4851

4952
if (clearHash && !import.meta.env.SSR)
5053
history.replaceState(null, '', window.location.href.split('#')[0])

.vitepress/theme/layouts/Layout.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import DocAside from '@/components/DocAside.vue'
99
import DocHeader from '@/components/DocHeader.vue'
1010
import DocReaction from '@/components/DocReaction.vue'
1111
import HighlightTargetedHeading from '@/components/HighlightTargetedHeading.vue'
12+
import LoginAlertDialog from '@/components/LoginAlertDialog.vue'
1213
import NavBarUserAvatar from '@/components/NavBarUserAvatar.vue'
1314
import { Notifications } from '@/components/ui'
1415
import { Sonner } from '@/components/ui/sonner'
@@ -140,6 +141,7 @@ router.onAfterRouteChange = setupMediumZoom
140141
<template #layout-bottom>
141142
<HighlightTargetedHeading />
142143
<Notifications />
144+
<LoginAlertDialog />
143145
</template>
144146
</Layout>
145147
</template>

src/components/forum/ForumLocalNav.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useMediaQuery, useTitle, useUrlSearchParams } from '@vueuse/core'
33
import { useData } from 'vitepress'
44
import { computed } from 'vue'
55
import LocalNav from '@/components/LocalNav.vue'
6-
import LoginAlertDialog from '@/components/LoginAlertDialog.vue'
76
import { Button } from '@/components/ui/button'
87
import {
98
HoverCard,
@@ -13,8 +12,8 @@ import {
1312
import { useLocalized } from '@/hooks/useLocalized'
1413
import { useUserAuthStore } from '@/stores/useUserAuth'
1514
import ForumPublishTopicForm from '~/components/forum/form/publish-topic-form/ForumPublishTopicForm.vue'
16-
import { publishTopic } from './utils'
1715
import { useRuleChecks } from '~/composables/useRuleChecks'
16+
import { publishTopic } from './utils'
1817
1918
const open = defineModel<boolean>('open-search-curtain', {
2019
default: false,
@@ -54,14 +53,16 @@ const selectPublishTopicMenu = computed(() => {
5453
label: message.value.forum.labels.submitBug,
5554
icon: 'i-lucide-bug',
5655
action: () => {
57-
location.hash = 'PUBLISH-TOPIC-BUG'
56+
location.hash = 'BUG'
57+
publishTopic()
5858
},
5959
},
6060
{
6161
label: message.value.forum.labels.submitSuggestion,
6262
icon: 'i-lucide-file-text',
6363
action: () => {
64-
location.hash = 'PUBLISH-TOPIC-FEAT'
64+
location.hash = 'FEAT'
65+
publishTopic()
6566
},
6667
},
6768
]
@@ -72,7 +73,8 @@ const selectPublishTopicMenu = computed(() => {
7273
label: '发公告',
7374
icon: 'i-lucide-megaphone',
7475
action: () => {
75-
location.hash = 'PUBLISH-TOPIC-ANN'
76+
location.hash = 'ANN'
77+
publishTopic()
7678
},
7779
})
7880
}
@@ -128,7 +130,6 @@ const selectPublishTopicMenu = computed(() => {
128130
<span class="i-lucide-plus z-9999 inline-block size-[1.75rem] shadow-[var(--vp-shadow-1)]" />
129131
</Button>
130132
<ForumPublishTopicForm />
131-
<LoginAlertDialog />
132133
</template>
133134
</Teleport>
134135
</template>

0 commit comments

Comments
 (0)