Skip to content

Commit

Permalink
fix(alipay): 修复支付宝小程序使用 CustomWrapper 失败的问题,fix #12496
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Sep 20, 2022
1 parent 2bac082 commit d747495
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions packages/shared/src/runtime-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ interface MiniLifecycle {
string[], /** others */
string[] /** side-effects */
]
component: [
string, /** attached */
string, /** detached */
]
}

interface MiniElementData {
Expand Down Expand Up @@ -98,6 +102,10 @@ const defaultMiniLifecycle: MiniLifecycle = {
'onShareAppMessage',
'onShareTimeline'
]
],
component: [
'attached',
'detached'
]
}

Expand Down
5 changes: 5 additions & 0 deletions packages/taro-alipay/src/runtime-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export * from './apis-list'
export * from './components'
export const hostConfig = {
initNativeApi,
getMiniLifecycle (config) {
config.component[0] = 'didMount'
config.component[1] = 'didUnmount'
return config
},
getEventCenter (Events) {
if (!my.taroEventCenter) {
my.taroEventCenter = new Events()
Expand Down
15 changes: 9 additions & 6 deletions packages/taro-runtime/src/dsl/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ export function createPageConfig (component: any, pageName?: string, data?: Reco
export function createComponentConfig (component: React.ComponentClass, componentName?: string, data?: Record<string, unknown>) {
const id = componentName ?? `taro_component_${pageId()}`
let componentElement: TaroRootElement | null = null
const [ ATTACHED, DETACHED ] = hooks.call('getMiniLifecycleImpl')!.component

const config: any = {
attached () {
[ATTACHED] () {
perf.start(PAGE_INIT)
const path = getPath(id, { id: this.getPageId?.() || pageId() })
Current.app!.mount!(component, path, () => {
Expand All @@ -266,7 +267,7 @@ export function createComponentConfig (component: React.ComponentClass, componen
}
})
},
detached () {
[DETACHED] () {
const path = getPath(id, { id: this.getPageId() })
Current.app!.unmount!(path, () => {
instances.delete(path)
Expand All @@ -293,16 +294,18 @@ export function createComponentConfig (component: React.ComponentClass, componen

export function createRecursiveComponentConfig (componentName?: string) {
const isCustomWrapper = componentName === CUSTOM_WRAPPER
const [ ATTACHED, DETACHED ] = hooks.call('getMiniLifecycleImpl')!.component

const lifeCycles = isCustomWrapper
? {
attached () {
const componentId = this.data.i?.sid
[ATTACHED] () {
const componentId = this.data.i?.sid || this.props.i?.sid
if (isString(componentId)) {
customWrapperCache.set(componentId, this)
}
},
detached () {
const componentId = this.data.i?.sid
[DETACHED] () {
const componentId = this.data.i?.sid || this.props.i?.sid
if (isString(componentId)) {
customWrapperCache.delete(componentId)
}
Expand Down

0 comments on commit d747495

Please sign in to comment.