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

【harmony-hybrid】解决返回时上一个页面瞬间白屏的问题 #15576

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/taro-router/src/router/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export default class PageHandler {
pageEl.style.zIndex = '1'
}

eventCenter.trigger('__taroPageWillShowAfterDestroyed')

this.unloadTimer = setTimeout(() => {
this.unloadTimer = null
this.lastUnloadPage?.onUnload?.()
Expand All @@ -235,6 +237,14 @@ export default class PageHandler {
if (delta >= 1) this.unload(stacks.last, delta)
}

willShow (page?: PageInstance | null) {
if (!page) return
const pageEl = this.getPageContainer(page)
if (pageEl) {
pageEl.classList.remove('taro_page_shade')
}
}

show (page?: PageInstance | null, pageConfig: Route = {}, pageNo = 0) {
if (!page) return

Expand Down
6 changes: 6 additions & 0 deletions packages/taro-router/src/router/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export function createRouter (
const delta = stacks.getDelta(pathname)
// NOTE: Safari 内核浏览器在非应用页面返回上一页时,会触发额外的 POP 事件,此处需避免当前页面被错误卸载
if (currentPage !== stacks.getItem(prevIndex)) {
eventCenter.once('__taroPageWillShowAfterDestroyed', () => {
if (prevIndex > -1) {
const pageInstance = stacks.getItem(prevIndex)
pageInstance && handler.willShow(pageInstance)
}
})
handler.unload(currentPage, delta, prevIndex > -1)
if (prevIndex > -1) {
eventCenter.once('__taroPageOnShowAfterDestroyed', () => {
Expand Down