fix: MathJax 在页面切换和部分初次加载导致的右键菜单异常 - #50
Closed
bfyes wants to merge 1 commit into
Closed
Conversation
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

fix: MathJax 在页面切换和部分初次加载导致的右键菜单异常
您好,感谢文档仓库的精心编写!我在自己的个人 Zensical 文档站中解决了上述问题,所以来提PR,希望能解决该站点同样的问题。
问题概述
在使用过程中,我发现 MathJax 右键菜单在页面切换和部分初次加载时出现异常。具体体现在菜单部分加载,页面被强制定位到顶部,且在多平台的浏览器中稳定触发,截图如下:
触发方式
页面被强制定位可能会影响阅读体验。该异常的触发方式包括:
问题分析
toml 配置文件中引入了 instant 特性,它们带来了浏览体验上的提升,同时带来了组件加载不全的问题。
原因在于 navigation.instant 通过 fetch 替换 DOM 而非整页加载,MathJax 的菜单状态(posted 标志)在 DOM 替换后失效,导致菜单 frame 无法正确挂载。
方案选择
理论上采用重新加载的手段需要慎重,但实测发现加入以下温和手段无效:
我实际加入的代码均经过多次构建测试与部署测试(在我的主页仓库中测试, 同样采用MathJax)。
最终方案:每次
document$事件触发时,拷贝一份干净的 MathJax 配置,移除旧 script 标签后重新插入。同时从zensical.toml的extra_javascript中移除 MathJax 的静态 CDN 引用,改由mathjax.js动态创建,避免首次加载时重复初始化。浏览器有 CDN 缓存,不会重复下载。实测无卡顿等异常现象发生。