Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: enable prefetch for dumi Link #315

Merged
merged 1 commit into from
Dec 6, 2024
Merged

Conversation

afc163
Copy link
Member

@afc163 afc163 commented Dec 6, 2024

搬一下 ant-design/ant-design#51922ant-design/ant-design#51921

Summary by CodeRabbit

发布说明

  • 新功能

    • 引入了新的链接组件,改善了链接的渲染和样式。
    • 添加了路由预取功能以提升导航性能。
  • Bug 修复

    • 移除了不必要的预取属性,简化了组件的链接渲染逻辑。
  • 文档

    • 更新了配置文件以反映新的路由和组件设置。
  • 样式

    • 组件的结构和样式保持不变,但链接的实现方式已更新。
  • 依赖管理

    • 移除了对 nprogress 的依赖,简化了项目依赖树。

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

📝 Walkthrough

Walkthrough

本次变更涉及多个组件的更新,主要集中在链接组件的导入路径和渲染逻辑的修改。MainBanner.tsxLocaleLinkFooter等组件均将Link组件的导入路径从dumi库更改为本地路径。此外,ComponentOverview组件移除了链接的prefetch属性,而DemoWrapper组件则添加了Suspense以支持异步渲染。整体结构和逻辑保持不变,主要是优化了组件的链接处理和异步加载。

Changes

文件路径 修改摘要
.dumi/pages/index/components/MainBanner.tsx 更新Link组件的导入路径,从dumi改为本地路径,其他逻辑保持不变。
.dumi/theme/builtins/ComponentOverview/index.tsx 移除Link组件的prefetch属性,保持其他渲染逻辑不变。
.dumi/theme/builtins/DemoWrapper/index.tsx 添加Suspense以支持异步渲染,重新排列导入顺序,其他逻辑保持不变。
.dumi/theme/builtins/LocaleLink/index.tsx 更新Link组件的导入路径,保持locale处理逻辑不变。
.dumi/theme/common/Link.tsx 更新LinkProps接口,移除过时的钩子,简化href计算逻辑,重命名handleClickonClick
.dumi/theme/slots/Footer/index.tsx 更新Link组件的导入路径,其他逻辑保持不变。
.dumirc.ts 添加routePrefetchmanifest属性,保持其他配置不变。
package.json 移除@types/nprogressnprogress依赖,简化依赖管理。

Possibly related PRs

Suggested reviewers

  • li-jia-nan

兔子欢快跳跃,
链接新路径到达,
异步渲染更流畅,
组件更新真精彩!
代码简化如春风,
兔子乐在其中。 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Dec 6, 2024

Preview is ready

Copy link

codecov bot commented Dec 6, 2024

Bundle Report

Bundle size has no change ✅

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
.dumi/theme/common/Link.tsx (1)

14-24: 链接组件实现优雅,建议小幅优化

组件的基本实现非常扎实,特别是对 ref 的转发处理。不过建议对 href 的计算逻辑做一些优化。

建议将 href 计算逻辑提取为独立函数:

+const getHref = (to: LinkProps['to'], pathname: string): string => {
+  if (typeof to === 'object') {
+    return `${to.pathname || pathname}${to.search || ''}${to.hash || ''}`;
+  }
+  return to;
+};

const Link = forwardRef<HTMLAnchorElement, React.PropsWithChildren<LinkProps>>(
  ({ component, children, to, ...rest }, ref) => {
    const { pathname } = useLocation();
    const { preloadRoute } = useAppData();
    const navigate = useNavigate();
-    const href = useMemo<string>(() => {
-      if (typeof to === 'object') {
-        return `${to.pathname || pathname}${to.search || ''}${to.hash || ''}`;
-      }
-      return to;
-    }, [to]);
+    const href = useMemo(() => getHref(to, pathname), [to, pathname]);
.dumi/theme/builtins/DemoWrapper/index.tsx (1)

109-111: 异步加载处理优化

添加 Suspense 包装很好地处理了 DumiDemoGrid 的异步加载,但建议添加 fallback 内容。

-        <Suspense>
+        <Suspense fallback={<div className="demo-loading">加载中...</div>}>
           <DumiDemoGrid items={demos} />
         </Suspense>
.dumirc.ts (1)

14-14: 建议补充 manifest 配置的具体内容

虽然空的 manifest 配置可以工作,但建议根据项目需求添加适当的配置,比如:

  • 缓存策略
  • 预加载规则
  • 资源优先级

这样可以更好地优化资源加载性能。

-  manifest: {},
+  manifest: {
+    // 建议添加以下配置
+    strategy: 'eager', // 或 'lazy'
+    basePath: '/',
+    publicPath: '/',
+  },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5321c19 and e8d6b01.

⛔ Files ignored due to path filters (1)
  • bun.lockb is excluded by !**/bun.lockb
📒 Files selected for processing (8)
  • .dumi/pages/index/components/MainBanner.tsx (1 hunks)
  • .dumi/theme/builtins/ComponentOverview/index.tsx (1 hunks)
  • .dumi/theme/builtins/DemoWrapper/index.tsx (2 hunks)
  • .dumi/theme/builtins/LocaleLink/index.tsx (1 hunks)
  • .dumi/theme/common/Link.tsx (1 hunks)
  • .dumi/theme/slots/Footer/index.tsx (1 hunks)
  • .dumirc.ts (1 hunks)
  • package.json (0 hunks)
💤 Files with no reviewable changes (1)
  • package.json
🔇 Additional comments (8)
.dumi/theme/builtins/LocaleLink/index.tsx (1)

4-4: 导入路径修改符合预期!

将 Link 组件的导入从 dumi 包改为本地路径是合理的重构,与其他文件保持一致。

.dumi/theme/common/Link.tsx (2)

25-34: 点击事件处理逻辑完善

处理了 metaKey/ctrlKey/shiftKey 以支持新标签页打开,同时正确区分了内部和外部链接。


48-51: 预加载功能配置正确

通过 prefetch 属性启用了 DumiLink 的预加载功能,这将改善页面导航性能。

.dumi/theme/builtins/DemoWrapper/index.tsx (1)

3-3: 导入顺序调整合理

将 React 相关导入与第三方库导入分开排序,提高了代码的组织性。

Also applies to: 6-6

.dumi/theme/builtins/ComponentOverview/index.tsx (1)

246-248: 代码变更正确!

Link 组件的使用符合预期,移除了 prefetch 属性以便使用 dumi 的默认预加载行为。

.dumi/pages/index/components/MainBanner.tsx (1)

3-3: 导入路径更新正确!

将 Link 组件的导入从 dumi 更改为本地路径是合理的,与其他文件保持一致。

Also applies to: 9-9

.dumi/theme/slots/Footer/index.tsx (1)

18-18: 导入路径修改合适!

Link 组件的导入路径更新符合项目规范,确保了组件引用的一致性。

Also applies to: 25-25

.dumirc.ts (1)

11-15: 新增的路由预加载配置看起来不错!

通过添加 routePrefetch 配置启用了 dumi 的路由预加载功能,这将改善页面导航性能。空对象配置是有效的,因为它使用了 dumi 的默认预加载行为。

建议在文档中添加关于此功能的说明,以便其他开发者了解如何正确使用 <Link prefetch /> 组件。

让我们验证一下相关组件是否正确使用了这个新功能:

Copy link

github-actions bot commented Dec 6, 2024

size-limit report 📦

Path Size
dist/antdx.min.js 40.67 KB

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.36%. Comparing base (5321c19) to head (e8d6b01).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #315   +/-   ##
=======================================
  Coverage   91.36%   91.36%           
=======================================
  Files          66       66           
  Lines        1447     1447           
  Branches      368      383   +15     
=======================================
  Hits         1322     1322           
  Misses        125      125           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@afc163 afc163 enabled auto-merge (squash) December 6, 2024 06:51
Copy link

Deploying ant-design-x with  Cloudflare Pages  Cloudflare Pages

Latest commit: e8d6b01
Status: ✅  Deploy successful!
Preview URL: https://5b5b7d00.ant-design-x.pages.dev
Branch Preview URL: https://docs-dumi-link-prefetch.ant-design-x.pages.dev

View logs

Copy link
Collaborator

@YumoImer YumoImer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@afc163 afc163 merged commit 9c2bf53 into main Dec 6, 2024
16 checks passed
@afc163 afc163 deleted the docs/dumi-link-prefetch branch December 6, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants