fix(diy): 从贴纸编辑页返回时 onShow 同步缓存最新贴纸

navigateBack 不触发工作台重新挂载,stickers state 停留在进入前的旧值,
编辑保存虽已写入缓存/服务端但工作台渲染的是旧 state。
useDidShow 从缓存同步当前设计贴纸(含 src/edits 变化),
首次 onShow 跳过(mount 读取端已做旧数据归一化)。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-09-12 19:44:16 +08:00
co-authored by Claude
parent cf02a10636
commit 418702295b
2 changed files with 16 additions and 1 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+15
View File
@@ -183,6 +183,21 @@ export default function DIYPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stickers])
// 问题5 留意点:页面栈返回(贴纸编辑页保存后 navigateBack)不触发重新挂载,
// 需在 onShow 从缓存同步最新贴纸(src/edits),否则工作台仍渲染旧 state。
// 首次 onShow 跳过——mount 读取端已做过旧数据归一化,避免被未归一化的缓存覆盖。
const skipShowRef = useRef(true)
Taro.useDidShow(() => {
if (skipShowRef.current) { skipShowRef.current = false; return }
const dId = latestRef.current.designId
if (!dId) return
const cached = getDesignList().find(d => d.id === dId)
const list = cached && cached.designData ? cached.designData.stickers : undefined
if (list && list.length) {
setStickers(checkOverlap(list))
}
})
// 矩形碰撞检测
const checkOverlap = (list: StickerItem[]) => {
const newList = list.map(s => ({ ...s, isOverlapping: false }))