WASM 下载完成后点击 TOC/标题 # 锚点会整页刷新且不滚动,而 SSR 阶段(WASM 未就绪)点击正常——这是 Dioxus 0.7 事件委托的副作用: 项目任意位置用 onclick(post_nav_links.rs)即触发 Dioxus 全局 click 委托。 点击 dangerous_inner_html 注入的 <a href="#id"> 时,事件冒泡到根监听器, handleEvent 发现 <a> 无 Dioxus onclick → 走兜底 handleClickNavigate: preventDefault 拦掉原生 fragment-scroll,再 browser_open IPC 把 hash 当 外部 URL 整页加载(History::external → location.set_href)。 修复:yggdrasil-core 新增 anchor-click.ts,在 window capture 阶段(早于 Dioxus 的 bubble 委托)拦截同页 hash 锚点点击,stopPropagation 阻止事件 到达 Dioxus,自行 scrollIntoView + replaceState 更新地址栏。中键/修饰键、 外链、目标不存在等情况放行原行为。 81682eb 的 scrollToHash 只在 PostContent 挂载时跑一次,不覆盖点击场景; 本修复与之正交,共同覆盖刷新与点击两条路径。initAnchorClick 幂等。
22 lines
754 B
TypeScript
22 lines
754 B
TypeScript
import { initAnchorClick } from './anchor-click';
|
|
import { scrollToHash } from './hash-scroll';
|
|
import { initPostContent } from './post-content';
|
|
import { applyResolvedTheme, startThemeTransition } from './theme-transition';
|
|
import './style.css';
|
|
|
|
declare global {
|
|
interface Window {
|
|
__initPostContent: (selector: string) => void;
|
|
__initAnchorClick: () => void;
|
|
__scrollToHash: () => void;
|
|
__startThemeTransition: (x: number, y: number) => void;
|
|
__applyResolvedTheme: (isDark: boolean) => void;
|
|
}
|
|
}
|
|
|
|
window.__initPostContent = initPostContent;
|
|
window.__initAnchorClick = initAnchorClick;
|
|
window.__scrollToHash = scrollToHash;
|
|
window.__startThemeTransition = startThemeTransition;
|
|
window.__applyResolvedTheme = applyResolvedTheme;
|