fix(chat): 增加 ResizeObserver 初始化延迟,避免首次挂载时侧边栏意外关闭

This commit is contained in:
Wenjie Zhang 2026-04-19 23:04:36 +08:00
parent 1b053f3cd4
commit b1700f2424

View File

@ -813,6 +813,8 @@ const scrollController = new ScrollController('.chat-main')
const chatMainRef = ref(null) const chatMainRef = ref(null)
const isSidebarFloating = ref(false) const isSidebarFloating = ref(false)
let chatMainResizeObserver = null let chatMainResizeObserver = null
// ResizeObserver
let isResizeObserverReady = false
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
@ -824,6 +826,9 @@ onMounted(() => {
if (window.ResizeObserver && chatMainRef.value) { if (window.ResizeObserver && chatMainRef.value) {
localUIState.chatMainWidth = chatMainRef.value.clientWidth || window.innerWidth localUIState.chatMainWidth = chatMainRef.value.clientWidth || window.innerWidth
chatMainResizeObserver = new ResizeObserver((entries) => { chatMainResizeObserver = new ResizeObserver((entries) => {
// layout
if (!isResizeObserverReady) return
for (const entry of entries) { for (const entry of entries) {
const width = entry.contentRect.width const width = entry.contentRect.width
localUIState.chatMainWidth = width localUIState.chatMainWidth = width
@ -846,6 +851,11 @@ onMounted(() => {
}) })
chatMainResizeObserver.observe(chatMainRef.value) chatMainResizeObserver.observe(chatMainRef.value)
} }
// 50ms ResizeObserver layout
setTimeout(() => {
isResizeObserverReady = true
}, 50)
}) })
setTimeout(() => { setTimeout(() => {
localUIState.isInitialRender = false localUIState.isInitialRender = false