From 58f83fa7e749a4a82c714d802e3f964c124e800e Mon Sep 17 00:00:00 2001 From: yyh <92089059+lyzno1@users.noreply.github.com> Date: Fri, 24 Jul 2026 23:30:52 +0800 Subject: [PATCH] refactor(web): remove obsolete route prefix handler (#39545) --- web/app/layout.tsx | 2 -- web/app/routePrefixHandle.tsx | 57 ----------------------------------- 2 files changed, 59 deletions(-) delete mode 100644 web/app/routePrefixHandle.tsx diff --git a/web/app/layout.tsx b/web/app/layout.tsx index 4618dc6ed5a..2a0f2cbf561 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -18,7 +18,6 @@ import { PartnerStackCookieRecorder } from './components/billing/partner-stack/c import { AgentationLoader } from './components/devtools/agentation-loader' import { ReactScanLoader } from './components/devtools/react-scan/loader' import { I18nServerProvider } from './components/provider/i18n-server' -import RoutePrefixHandle from './routePrefixHandle' import './styles/globals.css' import './styles/markdown.css' @@ -85,7 +84,6 @@ export default async function RootLayout({ children }: { children: React.ReactNo - diff --git a/web/app/routePrefixHandle.tsx b/web/app/routePrefixHandle.tsx deleted file mode 100644 index e153a085d75..00000000000 --- a/web/app/routePrefixHandle.tsx +++ /dev/null @@ -1,57 +0,0 @@ -'use client' - -import { useEffect } from 'react' -import { usePathname } from '@/next/navigation' -import { basePath } from '@/utils/var' - -export default function RoutePrefixHandle() { - const pathname = usePathname() - const handleRouteChange = () => { - const addPrefixToImg = (e: HTMLImageElement) => { - const url = new URL(e.src) - const prefix = url.pathname.slice(0, basePath.length) - if ( - prefix !== basePath && - !url.href.startsWith('blob:') && - !url.href.startsWith('data:') && - !url.href.startsWith('http') - ) { - url.pathname = basePath + url.pathname - e.src = url.toString() - } - } - // create an observer instance - const observer = new MutationObserver((mutationsList) => { - for (const mutation of mutationsList) { - if (mutation.type === 'childList') { - // listen for newly added img tags - mutation.addedNodes.forEach((node) => { - if ((node as HTMLElement).tagName === 'IMG') addPrefixToImg(node as HTMLImageElement) - }) - } else if ( - mutation.type === 'attributes' && - (mutation.target as HTMLElement).tagName === 'IMG' - ) { - // if the src of an existing img tag changes, update the prefix - if (mutation.attributeName === 'src') addPrefixToImg(mutation.target as HTMLImageElement) - } - } - }) - - // configure observation options - const config = { - childList: true, - attributes: true, - subtree: true, - attributeFilter: ['src'], - } - - observer.observe(document.body, config) - } - - useEffect(() => { - if (basePath) handleRouteChange() - }, [pathname]) - - return null -}