Skip to content

Commit

Permalink
fix: 解决返回时上一个页面瞬间白屏的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
heweishui committed Apr 23, 2024
1 parent cc92f7f commit e83953e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit e83953e

Please sign in to comment.