Add progress bar to page loading.#1030
Merged
Merged
Conversation
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.
🤖 Auto-generated by Endless task #21.
Initiated by: Huacnlee Li Huashun
背景
VitePress 站点采用客户端单页导航(SPA),用户点击内部链接后,页面内容需要通过网络请求加载。在网速较慢的情况下,点击链接后会有一段时间页面没有任何视觉反馈,用户无法判断是否点击成功、是否正在加载。
这一问题在海外用户访问时尤为明显,因为服务器位于香港,部分地区的延迟可能达到数百毫秒到几秒。缺少加载指示会导致用户重复点击或误以为网站出现故障。
摘要
useProgressBar.ts组合式模块,封装进度条的响应式状态和startProgress/finishProgress控制函数ProgressBar.vue组件,以position: fixed固定在视口顶部,使用主题品牌色渲染 2px 高度进度条theme/index.ts,在 VitePress 路由onBeforeRouteChange触发startProgress(),在onAfterRouteChange触发finishProgress()并保留原有saveInviteCodeFromUrl逻辑LayoutInner.vue,在布局顶部引入并渲染<ProgressBar />provide/inject,且 SSR 阶段visible初始为false,不会影响静态构建current + (85 - current) * 0.1)使进度条在快速和慢速网络下均表现自然,与 GitHub、YouTube 等主流实现一致code/developers/目录运行bun run dev--vp-c-brand-1/--vp-c-brand-2CSS 变量修改
docs/.vitepress/theme/composables/useProgressBar.tsdocs/.vitepress/theme/components/ProgressBar.vuedocs/.vitepress/theme/index.tsuseProgressBar导入,将路由钩子替换为链式调用(进度条 + 原有 invite-code 逻辑)docs/.vitepress/theme/layouts/LayoutInner.vuelayout-topslot 后渲染<ProgressBar />关键决策
不引入 nprogress 等第三方库——其核心逻辑与本实现等价,但需额外的 npm 依赖、类型声明和样式覆盖。自定义实现代码量极小,且可直接使用 VitePress 主题的 CSS 变量保持视觉一致性。