fix(hooks): [use-lockscreen] fix lock-scroll not working (#19711)

* fix(hooks): [use-lockscreen] fix lock-scroll not working

closed #19708

* fix(hooks): update

* chore: add test

---------

Co-authored-by: qiang <qw13131wang@gmail.com>
This commit is contained in:
Meet you
2025-10-30 17:47:37 +08:00
committed by GitHub
parent bf138bcc11
commit b82d8575e7
2 changed files with 22 additions and 5 deletions

View File

@@ -105,4 +105,26 @@ describe('useLockscreen', () => {
wrapper.unmount()
})
it('should not cleanup when newly created during the closing process', async () => {
const wrapper1 = mount({
setup: () => () => <Comp />,
})
await nextTick()
expect(hasClass(document.body, kls)).toBe(true)
wrapper1.unmount()
const wrapper2 = mount({
setup: () => () => <Comp />,
})
vi.advanceTimersByTime(250)
await nextTick()
expect(hasClass(document.body, kls)).toBe(true)
wrapper2.unmount()
vi.advanceTimersByTime(250)
await nextTick()
expect(hasClass(document.body, kls)).toBe(false)
})
})

View File

@@ -4,7 +4,6 @@ import {
getScrollBarWidth,
getStyle,
hasClass,
isClient,
removeClass,
throwError,
} from '@element-plus/utils'
@@ -38,10 +37,6 @@ export const useLockscreen = (
const hiddenCls = computed(() => ns.bm('parent', 'hidden'))
if (!isClient || hasClass(document.body, hiddenCls.value)) {
return
}
let scrollBarWidth = 0
let withoutHiddenClass = false
let bodyWidth = '0'