BetaSu / just-react

「React技术揭秘」 一本自顶向下的React源码分析书
https://react.iamkasong.com/
MIT License
6.13k stars 542 forks source link

beginWork和completeWork的疑问 #118

Open liuyisnake opened 2 years ago

liuyisnake commented 2 years ago

https://react.iamkasong.com/process/reconciler.html#%E4%BE%8B%E5%AD%90

看图上所示的每个component都会执行到beginWork和completeWork,但实际上并不是这样的 completeWork只有在child没有的时候才会执行,然后找到fiber树上一个有slibing的组件执行beginWork 这样并不是所有组件都会有completeWork

尝试打印了下自己的代码大概如下

beginWork App scheduler.development.js:468 beginWork RecoilRoot scheduler.development.js:468 beginWork RecoilRoot_INTERNAL 2scheduler.development.js:468 beginWork undefined scheduler.development.js:468 beginWork Batcher scheduler.development.js:468 completeUnitOfWork Batcher scheduler.development.js:468 beginWork GlobalThemeProvider scheduler.development.js:468 beginWork undefined scheduler.development.js:468 beginWork ThemeProvider 2scheduler.development.js:468 beginWork undefined scheduler.development.js:468 beginWork CssBaseline scheduler.development.js:468 beginWork LanguageProvider scheduler.development.js:468 beginWork undefined scheduler.development.js:468 beginWork ThemeProvider scheduler.development.js:468 beginWork undefined scheduler.development.js:468 beginWork Initer scheduler.development.js:468 beginWork SnackbarProvider scheduler.development.js:468 beginWork undefined scheduler.development.js:468 beginWork AxiosIniter scheduler.development.js:468 completeUnitOfWork AxiosIniter scheduler.development.js:468 beginWork null scheduler.development.js:468 completeUnitOfWork null