From 26bd40d80421b32fd63ab27fabc7d4e485a457ff Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 8 Feb 2026 01:11:05 +0900 Subject: [PATCH] #140 --- frontend/src/components/TopNav.tsx | 2 +- frontend/src/lib/prefetchers.ts | 18 ++++++++++++++---- frontend/src/lib/wiki.ts | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/TopNav.tsx b/frontend/src/components/TopNav.tsx index 81816f2..144f517 100644 --- a/frontend/src/components/TopNav.tsx +++ b/frontend/src/components/TopNav.tsx @@ -65,7 +65,7 @@ export default (({ user }: Props) => { const postCount = tag?.postCount ?? 0 const wikiPageFlg = Boolean (/^\/wiki\/(?!new|changes)[^\/]+/.test (location.pathname) && wikiId) - const wikiTitle = location.pathname.split ('/')[2] + const wikiTitle = location.pathname.split ('/')[2] ?? '' const menu: Menu = [ { name: '広場', to: '/posts', subMenu: [ { name: '一覧', to: '/posts' }, diff --git a/frontend/src/lib/prefetchers.ts b/frontend/src/lib/prefetchers.ts index f034459..d61291e 100644 --- a/frontend/src/lib/prefetchers.ts +++ b/frontend/src/lib/prefetchers.ts @@ -4,7 +4,9 @@ import { match } from 'path-to-regexp' import { fetchPost, fetchPosts, fetchPostChanges } from '@/lib/posts' import { postsKeys, tagsKeys, wikiKeys } from '@/lib/queryKeys' import { fetchTagByName } from '@/lib/tags' -import { fetchWikiPageByTitle, fetchWikiPages } from '@/lib/wiki' +import { fetchWikiPage, + fetchWikiPageByTitle, + fetchWikiPages } from '@/lib/wiki' type Prefetcher = (qc: QueryClient, url: URL) => Promise @@ -33,11 +35,19 @@ const prefetchWikiPageShow: Prefetcher = async (qc, url) => { queryKey: wikiKeys.show (title, { version }), queryFn: () => fetchWikiPageByTitle (title, { version }) }) - if (wikiPage?.body) + if (wikiPage) { + const effectiveId = String (wikiPage.id ?? '') await qc.prefetchQuery ({ - queryKey: wikiKeys.index ({ }), - queryFn: () => fetchWikiPages ({ }) }) + queryKey: wikiKeys.show (effectiveId, { }), + queryFn: () => fetchWikiPage (effectiveId, { } ) }) + + if (wikiPage.body) + { + await qc.prefetchQuery ({ + queryKey: wikiKeys.index ({ }), + queryFn: () => fetchWikiPages ({ }) }) + } } const effectiveTitle = wikiPage?.title ?? title diff --git a/frontend/src/lib/wiki.ts b/frontend/src/lib/wiki.ts index 2899dad..276db3a 100644 --- a/frontend/src/lib/wiki.ts +++ b/frontend/src/lib/wiki.ts @@ -22,7 +22,7 @@ export const fetchWikiPageByTitle = async ( ): Promise => { try { - return await apiGet (`/wiki/title/${ title }`, { params: { version } }) + return await apiGet (`/wiki/title/${ encodeURIComponent (title) }`, { params: { version } }) } catch {