dumi icon indicating copy to clipboard operation
dumi copied to clipboard

fix: default theme invalid time error

Open avennn opened this issue 2 years ago • 4 comments

🤔 这个变动的性质是?/ What is the nature of this change?

  • [ ] 新特性提交 / New feature
  • [x] bug 修复 / Fix bug
  • [ ] 样式优化 / Style optimization
  • [ ] 代码风格优化 / Code style optimization
  • [ ] 性能优化 / Performance optimization
  • [ ] 构建优化 / Build optimization
  • [ ] 网站、文档、Demo 改进 / Website, documentation, demo improvements
  • [ ] 重构代码或样式 / Refactor code or style
  • [ ] 测试相关 / Test related
  • [ ] 其他 / Other

🔗 相关 Issue / Related Issue

暂无相关issue,复现demo,操作步骤demo的README.md有描述

💡 需求背景和解决方案 / Background or solution

问题:使用dumi开发文档系统时,因为组件有使用到date-time-format-timezone,在组件文档路由切换过程中报错。

原因:date-time-format-timezone polyfill了Date对象的toLocaleDateString,最终使用Intl.DateTimeFormat来格式化时间。而默认主题的layout.tsx文件中,const updatedTimeIns = new Date(meta.updatedTime)在组件切换过程meta.updatedTime有可能为undefined,对应updatedTimeIns为Invalid Date对象,调用toLocaleDateString(实际Intl.DateTimeFormat)就会报错: image

修复方式: 当meta.updatedTime为undefined时,生成的updatedTime为”Invalid Date Invalid Date",展示在页面上没有意义 所以,只有当meta.updatedTime有值时才执行原来的格式化的逻辑。

📝 更新日志 / Changelog

Language Changelog
🇺🇸 English fix invalid date error when switch between component routes
🇨🇳 Chinese 修复切换组件路由时invalid date的错误

avennn avatar Jun 24 '22 15:06 avennn

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
dumi ❌ Failed (Inspect) Jun 24, 2022 at 3:58PM (UTC)

vercel[bot] avatar Jun 24 '22 15:06 vercel[bot]

🎊 PR Preview has been successfully built and deployed to https://dumi-preview-pr-1116.surge.sh

github-actions[bot] avatar Jun 24 '22 15:06 github-actions[bot]

🎊 PR Mobile Preview has been successfully built and deployed to https://dumi-mobile-preview-pr-1116.surge.sh

github-actions[bot] avatar Jun 24 '22 15:06 github-actions[bot]

Codecov Report

Merging #1116 (f859b67) into master (202b2c8) will decrease coverage by 0.12%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1116      +/-   ##
==========================================
- Coverage   95.06%   94.93%   -0.13%     
==========================================
  Files         119      119              
  Lines        2937     2942       +5     
  Branches      972     1003      +31     
==========================================
+ Hits         2792     2793       +1     
- Misses        141      145       +4     
  Partials        4        4              
Impacted Files Coverage Δ
packages/theme-default/src/layout.tsx 94.54% <100.00%> (+0.10%) :arrow_up:
packages/theme-default/src/builtins/Previewer.tsx 87.83% <0.00%> (-5.02%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 202b2c8...f859b67. Read the comment docs.

codecov[bot] avatar Jul 04 '22 02:07 codecov[bot]

❤️ 感谢贡献,dumi v1 不再更新,PR 将会关闭;dumi v2 已发布,欢迎继续参与 dumi 的建设,https://d.umijs.org/

PeachScript avatar Jan 28 '23 09:01 PeachScript