fix(diy): 从贴纸编辑页返回时 onShow 同步缓存最新贴纸
navigateBack 不触发工作台重新挂载,stickers state 停留在进入前的旧值, 编辑保存虽已写入缓存/服务端但工作台渲染的是旧 state。 useDidShow 从缓存同步当前设计贴纸(含 src/edits 变化), 首次 onShow 跳过(mount 读取端已做旧数据归一化)。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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 }))
|
||||
|
||||
Reference in New Issue
Block a user