-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix: 修复百度小程序 onLoad onTabItemTap执行时序问题 #18682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,7 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco | |
| } | ||
| } | ||
|
|
||
| const isSWAN = process.env.TARO_ENV === 'swan'// 百度小程序 | ||
| LIFECYCLES.forEach((lifecycle) => { | ||
| let isDefer = false | ||
| let isEvent = false | ||
|
|
@@ -258,6 +259,10 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco | |
| } else { | ||
| config[lifecycle] = function () { | ||
| const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments) | ||
| if (isSWAN) { | ||
| return exec() | ||
| } | ||
|
Comment on lines
+262
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for LIFECYCLES definition in the file
rg -n "LIFECYCLES" packages/taro-runtime/src/dsl/common.ts -A 30 -B 5Repository: NervJS/taro Length of output: 3434 🏁 Script executed: # Search for defer: usage across the codebase
rg -n "defer:" --type ts -C 2Repository: NervJS/taro Length of output: 2811 🏁 Script executed: # Get context around lines 262-270 to see the full conditional logic
sed -n '250,280p' packages/taro-runtime/src/dsl/common.tsRepository: NervJS/taro Length of output: 948 🏁 Script executed: # Search for onTabItemTap references
rg -n "onTabItemTap|TabItemTap" --type ts -C 3Repository: NervJS/taro Length of output: 23101 为 Swan 平台添加解释性注释,说明为何需要绕过 当前实现确实使百度小程序环境下所有生命周期都立即执行。虽然 建议:
🤖 Prompt for AI Agents |
||
|
|
||
| if (isDefer) { | ||
| hasLoaded.then(exec) | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NervJS/taro
Length of output: 826
🏁 Script executed:
Repository: NervJS/taro
Length of output: 126
🏁 Script executed:
Repository: NervJS/taro
Length of output: 1857
🏁 Script executed:
Repository: NervJS/taro
Length of output: 1241
🏁 Script executed:
Repository: NervJS/taro
Length of output: 7225
🏁 Script executed:
Repository: NervJS/taro
Length of output: 6261
🏁 Script executed:
Repository: NervJS/taro
Length of output: 315
🏁 Script executed:
Repository: NervJS/taro
Length of output: 3118
🏁 Script executed:
Repository: NervJS/taro
Length of output: 2769
🏁 Script executed:
Repository: NervJS/taro
Length of output: 2944
🏁 Script executed:
Repository: NervJS/taro
Length of output: 210
🏁 Script executed:
Repository: NervJS/taro
Length of output: 398
🏁 Script executed:
Repository: NervJS/taro
Length of output: 204
🏁 Script executed:
Repository: NervJS/taro
Length of output: 3553
🏁 Script executed:
Repository: NervJS/taro
Length of output: 2765
环境检测方式正确,但应确认对所有生命周期的影响
使用
process.env.TARO_ENV === 'swan'是 Taro 框架检测百度小程序环境的标准方式。然而,第 262-264 行的修复会对 LIFECYCLES 数组中的所有生命周期立即执行,完全绕过 defer 机制。这包括 onPullDownRefresh、onReachBottom、onPageScroll 等。建议确认这是否为预期行为,以及是否可能对其他需要延迟执行的生命周期产生副作用。
🤖 Prompt for AI Agents