umijs / plugin-access

Umi plugin for access management.
MIT License
32 stars 3 forks source link

feat: 确保 initial state 加载完后再继续渲染 #2

Closed jtsang4 closed 4 years ago

jtsang4 commented 4 years ago

问题:

当 initial state 未加载完时,initial state 的初值是 undefined,如果在 access.ts 中对 initial 进行解构值会造成 crash。

分析:

initial state 与一般页面数据不同,可以认为整个应用都会依赖它加载完后才能进入应用逻辑,所以在加载完之前不应该继续渲染和创建 access 实例。

这样的话在 plugin-initial-state 中应将初始 loading 状态设为 true,plugin-access 如果拿到 loading 为 true 则停止往下执行,直到 loading 完成后再创建 access 实例以及往下渲染。

具体做法:

增加一层 InitialStatePasser 确保 initial state 的加载和控制应用的执行渲染。

codecov[bot] commented 4 years ago

Codecov Report

Merging #2 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@         Coverage Diff         @@
##           master   #2   +/-   ##
===================================
  Coverage       0%   0%           
===================================
  Files           6    6           
  Lines          40   40           
  Branches        5    5           
===================================
  Misses         40   40
Impacted Files Coverage Δ
src/utils/getAccessProviderContent.ts 0% <ø> (ø) :arrow_up:

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 eb27aa8...937f8b4. Read the comment docs.

jtsang4 commented 4 years ago

loading 处理已放到 plugin-initial-state

当前 PR 所做的事:

  1. 当 access 实例为 nullish 的值时,在开发环境 log 出相应的警告
  2. 更新和丰富 README