Skip to content

fix: 【发行为混合分包】TypeError: t.$callHook is not a function #4829

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/uni-mp-core/src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export function initCreateSubpackageApp(parseAppOptions?: ParseAppOptions) {
})
if (!app) return
;(vm.$ as any).ctx.$scope = app
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigning '$hasHook' and '$callHook' synchronously resolves the async race condition that previously resulted in 't.$callHook is not a function'. Consider adding a comment explaining why these assignments are done here for future maintainability.

Suggested change
;(vm.$ as any).ctx.$scope = app
;(vm.$ as any).ctx.$scope = app
// Assigning `$hasHook` and `$callHook` synchronously is critical to prevent
// an async race condition that could result in `t.$callHook is not a function`.
// Do not modify the order or timing of these assignments without understanding
// the potential impact on app lifecycle hooks.

Copilot uses AI. Check for mistakes.

(vm.$ as any).ctx.$hasHook = hasHook
(vm.$ as any).ctx.$callHook = callHook
const globalData = app.globalData
if (globalData) {
Object.keys(appOptions.globalData).forEach((name) => {
Expand Down