Skip to content
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
35 changes: 20 additions & 15 deletions packages/uni-h5/src/framework/setup/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,7 @@ export function onPageShow(
instance: ComponentInternalInstance,
pageMeta: UniApp.PageRouteMeta
) {
if (__X__) {
const type = instance.type as { styleIsolation?: string }
if (type.styleIsolation !== 'isolated') {
const scopeId = getScopeId(instance.root)
scopeId && updateCurPageBodyScopeId(scopeId)
}
}
updateCurPageBodyScopeId(instance)
updateBodyScopeId(instance)
updateCurPageCssVar(pageMeta)
updateCurPageAttrs(pageMeta)
Expand All @@ -311,17 +305,28 @@ export function onPageShow(
}

export function onPageReady(instance: ComponentInternalInstance) {
const scopeId = getScopeId(instance)
scopeId && updateCurPageBodyScopeId(scopeId)
if (!updateCurPageBodyScopeId(instance) && __DEV__) {
console.warn('uni-page-body not found')
}
}

function updateCurPageBodyScopeId(scopeId: string) {
const pageBodyEl = document.querySelector('uni-page-body')
if (pageBodyEl) {
pageBodyEl.setAttribute(scopeId, '')
} else if (__DEV__) {
console.warn('uni-page-body not found')
function updateCurPageBodyScopeId(instance: ComponentInternalInstance) {
const pageRoot = getPageInstanceByChild(instance)?.subTree
?.el as Element | null
const pageBodyEl = pageRoot?.querySelector?.('uni-page-body')
if (!pageBodyEl) {
return false
}

const type = instance.type as { styleIsolation?: string }
if (__X__ && type.styleIsolation !== 'isolated') {
const appScopeId = getScopeId(instance.root)
appScopeId && pageBodyEl.setAttribute(appScopeId, '')
}

const pageScopeId = getScopeId(instance)
pageScopeId && pageBodyEl.setAttribute(pageScopeId, '')
return true
}

function getScopeId(instance: ComponentInternalInstance) {
Expand Down
Loading