Skip to content

Commit c13e6e8

Browse files
committed
fix(wx-react): 修正didMount ,didFocus的执行顺序
1 parent 5189ba2 commit c13e6e8

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/wx-react/miniprogram_dist/AllComponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class Component extends BaseComponent {
332332

333333
render(subVnode, this, context, this._r, this._or, '_r')
334334

335-
// 一般发生于didFoucs里面的setState,此时还未调用firstUpdate
335+
// firstRender既不是DONE,也不是PENDING,此时调用setState需要刷新_r数据
336336
if (this.firstRender !== FR_DONE) {
337337
return
338338
}

packages/wx-react/miniprogram_dist/WxNormalComp.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {render, createElement, HocComponent, unstable_batchedUpdates} from "./index"
1010
import geneUUID from "./geneUUID"
1111
import instanceManager from "./InstanceManager"
12-
import {recursionUnmount} from './util'
12+
import {FR_DONE, recursionUnmount} from './util'
1313

1414

1515
export default function (CompMySelf, RNApp) {
@@ -97,7 +97,9 @@ export default function (CompMySelf, RNApp) {
9797

9898
o.methods.onShow = function () {
9999
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
100-
compInst.componentDidFocus && unstable_batchedUpdates(() => {
100+
101+
//如果组件还未初始化 didFocus方法,由firstUpdateUI负责
102+
compInst.firstRender === FR_DONE && compInst.componentDidFocus && unstable_batchedUpdates(() => {
101103
compInst.componentDidFocus()
102104
})
103105
}

packages/wx-react/miniprogram_dist/util.js

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ export function recursionMount(comp) {
118118
}
119119
comp.firstRender = FR_DONE
120120
comp.componentDidMount && comp.componentDidMount()
121+
122+
if (comp.isPageComp && !comp.hocWrapped && comp.componentDidFocus) {
123+
comp.componentDidFocus()
124+
}
125+
121126
comp.firstRenderRes && comp.firstRenderRes()
122127
}
123128

0 commit comments

Comments
 (0)