Skip to content
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

fix: 修复 pageId 装载和卸载逻辑不一致的问题 #14179

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Changes from 2 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
10 changes: 8 additions & 2 deletions packages/taro-runtime/src/dsl/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,17 @@ 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 pageIdCache: string | null = null
Chen-jj marked this conversation as resolved.
Show resolved Hide resolved
let componentElement: TaroRootElement | null = null
const [ ATTACHED, DETACHED ] = hooks.call('getMiniLifecycleImpl')!.component

const config: any = {
[ATTACHED] () {
perf.start(PAGE_INIT)
const path = getPath(id, { id: this.getPageId?.() || pageId() })
xuanzebin marked this conversation as resolved.
Show resolved Hide resolved
pageIdCache = this.getPageId?.() || pageId()

const path = getPath(id, { id: pageIdCache })

Current.app!.mount!(component, path, () => {
componentElement = env.document.getElementById<TaroRootElement>(path)
ensure(componentElement !== null, '没有找到组件实例。')
Expand All @@ -298,7 +302,9 @@ export function createComponentConfig (component: React.ComponentClass, componen
})
},
[DETACHED] () {
const path = getPath(id, { id: this.getPageId() })
const path = getPath(id, { id: pageIdCache })

pageIdCache = null
Current.app!.unmount!(path, () => {
instances.delete(path)
if (componentElement) {
Expand Down