fix(cache): 远程参考图缓存改成读当前视图(修首帧闭包导致从未生效)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 44s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 44s
This commit is contained in:
1 parent
afbd04938a
commit
00fca7b112
6 files changed
+14
-6
No files matched your search
@@ -6636,10 +6636,14 @@ const tbCenterSeed = (type, refs) => {
|
||||
const [thumbRev, setThumbRev] = React.useState(0) // v3.87.7:显示缩略图就绪后触发一次 re-render(必须在 Workbench 内)
|
||||
useEffect(() => { wThumbBump = () => setThumbRev((v) => v + 1); return () => { wThumbBump = null } }, [])
|
||||
// 启动维护(v3.25.80):8 秒后做缩略图封顶 + legacy 未引用清理;同时启动远程参考图本地缓存。
|
||||
// 2026-12-04:这里必须用 ref 读「当前」视图状态。effect 依赖是 [],直接闭包 loaded/shellView
|
||||
// 拿到的是首帧值(loaded=false)⇒ enabled 永远 false,远程参考图缓存从未真正跑起来(用户实测无 localRef
|
||||
// 的根因)。ref 每帧同步,getState 每次都读最新值。
|
||||
const cacheUiRef = React.useRef({ loaded: false, shellView: 'home' })
|
||||
useEffect(() => {
|
||||
const RC = (typeof window !== 'undefined') ? window.IWBImageRemoteCache : null
|
||||
const stop = (RC && typeof RC.attach === 'function')
|
||||
? RC.attach({ getState: () => ({ enabled: !!(loaded && shellView === 'canvas'), nodes: (refs && refs.nodes) || [] }), writeRef: (u) => wImgRefWrite(u), updateNode: (id, patch) => updateNode(id, patch), fetchBlob: (u) => wRustFetchBlob(u) })
|
||||
? RC.attach({ getState: () => ({ enabled: !!(cacheUiRef.current.loaded && cacheUiRef.current.shellView === 'canvas'), nodes: (refs && refs.nodes) || [] }), writeRef: (u) => wImgRefWrite(u), updateNode: (id, patch) => updateNode(id, patch), fetchBlob: (u) => wRustFetchBlob(u) })
|
||||
: null
|
||||
const timer = setTimeout(() => {
|
||||
try { const F = wStoreMod(); if (F && typeof F.maintain === 'function') F.maintain({ maxMB: 300, keep: wCollectRefImageNames(workspaces) }).catch(() => { /* ignore */ }) } catch (e) { /* ignore */ }
|
||||
@@ -6687,6 +6691,8 @@ const tbCenterSeed = (type, refs) => {
|
||||
return () => { try { delete window.__IWB_E2E_HISTORY__; delete window.__IWB_E2E_CANVAS__; delete window.__IWB_E2E_SETREF__; delete window.__IWB_E2E_PUSH_HISTORY__ } catch (e) { /* ignore */ } }
|
||||
}, [])
|
||||
const [shellView, setShellView] = useState(() => { try { return lsRawGet('iwb_shell_view', null) === 'canvas' ? 'canvas' : 'home' } catch (e) { return 'home' } }) // landing=首页说明,home=我的画布,canvas=无限画布;刷新时恢复上次所在的视图
|
||||
// 2026-12-04:远程参考图缓存的 getState 在 [] effect 里,必须从 ref 读最新视图(此处已过 shellView 初始化)
|
||||
useEffect(() => { cacheUiRef.current.loaded = loaded; cacheUiRef.current.shellView = shellView }, [loaded, shellView])
|
||||
const [pluginPage, setPluginPage] = useState(null) // 插件整页:{pluginId,pageId};仅 pages 能力注册的页面
|
||||
// 插件被禁用/页面被移除时,若正停在该页,回到画布(避免空白页)
|
||||
React.useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user