Skip to content

Commit

Permalink
fix(react): 修复容器事件重复触发时导致的生命周期执行顺序异常的问题 (#15663)
Browse files Browse the repository at this point in the history
* fix(react): 修复容器事件重复触发时导致的生命周期执行顺序异常的问题

- 修复 waitAppWrapper 可能出现的同步和异步任务执行顺序导致生命周期执行顺序异常的问题

* fix(react): 修复小程序 unLoad 后 Taro unmount 的运行问题

---------

Co-authored-by: ZEJIA LIU <[email protected]>
  • Loading branch information
koppthe and ZEJIA-LIU authored May 7, 2024
1 parent 9e5c328 commit 6dcd5a1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/taro-plugin-react/src/runtime/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ export function createReactApp (
}

function waitAppWrapper (cb: () => void) {
appWrapper ? cb() : appWrapperPromise.then(() => cb())
/**
* 当同个事件触发多次时,waitAppWrapper 会出现同步和异步任务的执行顺序问题,
* 导致某些场景下 onShow 会优于 onLaunch 执行
*/
appWrapperPromise.then(() => cb())
// appWrapper ? cb() : appWrapperPromise.then(() => cb())
}

function renderReactRoot () {
Expand Down Expand Up @@ -275,7 +280,11 @@ export function createReactApp (
},

unmount (id: string, cb: () => void) {
appWrapper.unmount(id, cb)
if (appWrapper) {
appWrapper.unmount(id, cb)
} else {
appWrapperPromise.then(appWrapper => appWrapper.unmount(id, cb))
}
}
}, {
config: setDefaultDescriptor({
Expand Down

0 comments on commit 6dcd5a1

Please sign in to comment.