From d15a884a0d43e3599104c782fbe2ba0b6c3b5e57 Mon Sep 17 00:00:00 2001 From: MrWangJustToDo <2711470541@qq.com> Date: Sat, 9 Nov 2024 00:12:24 +0800 Subject: [PATCH] fix --- chrome/public/bundle/detector.js | 20 ++++++++----------- chrome/public/bundle/hook.js | 20 ++++++++----------- chrome/public/bundle/panel.js | 20 ++++++++----------- chrome/public/bundle/proxy.js | 20 ++++++++----------- chrome/public/bundle/service-worker.js | 20 ++++++++----------- chrome/src/components/HookView.tsx | 4 ++-- chrome/src/hooks/useDetailNode.ts | 4 ++++ chrome/src/hooks/useTreeNode.ts | 14 ++++++++++++- packages/core/src/data.ts | 27 ++++++++++++++------------ 9 files changed, 74 insertions(+), 75 deletions(-) diff --git a/chrome/public/bundle/detector.js b/chrome/public/bundle/detector.js index db58a9f..51a7fe5 100644 --- a/chrome/public/bundle/detector.js +++ b/chrome/public/bundle/detector.js @@ -719,6 +719,7 @@ var id$1 = 1; var loadById = false; var valueMap = new Map(); + var idMap = new Map(); var cacheMap = new WeakMap(); var getType = function (value) { if (isInBrowser && value && value instanceof Element) { @@ -749,8 +750,10 @@ if (deep === void 0) { deep = 3; } // full deep to load if (deep === 0) { - var currentId = id$1++; + var existId = idMap.get(value); + var currentId = existId || id$1++; valueMap.set(currentId, value); + idMap.set(value, currentId); return { i: currentId, t: type, @@ -820,17 +823,10 @@ }; var getNodeWithCache = function (value, type, deep) { if (deep === void 0) { deep = 3; } - var cache = cacheMap.get(value); - if (cache) { - // check circular reference - if (loadById) { - return { - t: type, - n: "".concat(cache.n || cache.t, " (Circular Reference)"), - c: true, - v: cache.v, - e: true, - }; + if (loadById) { + var cache = cacheMap.get(value); + if (cache) { + return __assign(__assign({}, cache), { c: true }); } } var v = getTargetNode(value, type, deep); diff --git a/chrome/public/bundle/hook.js b/chrome/public/bundle/hook.js index c96b249..0da1a44 100644 --- a/chrome/public/bundle/hook.js +++ b/chrome/public/bundle/hook.js @@ -792,6 +792,7 @@ var id$1 = 1; var loadById = false; var valueMap = new Map(); + var idMap = new Map(); var cacheMap = new WeakMap(); var getType = function (value) { if (isInBrowser && value && value instanceof Element) { @@ -822,8 +823,10 @@ if (deep === void 0) { deep = 3; } // full deep to load if (deep === 0) { - var currentId = id$1++; + var existId = idMap.get(value); + var currentId = existId || id$1++; valueMap.set(currentId, value); + idMap.set(value, currentId); return { i: currentId, t: type, @@ -893,17 +896,10 @@ }; var getNodeWithCache = function (value, type, deep) { if (deep === void 0) { deep = 3; } - var cache = cacheMap.get(value); - if (cache) { - // check circular reference - if (loadById) { - return { - t: type, - n: "".concat(cache.n || cache.t, " (Circular Reference)"), - c: true, - v: cache.v, - e: true, - }; + if (loadById) { + var cache = cacheMap.get(value); + if (cache) { + return __assign(__assign({}, cache), { c: true }); } } var v = getTargetNode(value, type, deep); diff --git a/chrome/public/bundle/panel.js b/chrome/public/bundle/panel.js index e905e03..0df2689 100644 --- a/chrome/public/bundle/panel.js +++ b/chrome/public/bundle/panel.js @@ -790,6 +790,7 @@ var id$1 = 1; var loadById = false; var valueMap = new Map(); + var idMap = new Map(); var cacheMap = new WeakMap(); var getType = function (value) { if (isInBrowser && value && value instanceof Element) { @@ -820,8 +821,10 @@ if (deep === void 0) { deep = 3; } // full deep to load if (deep === 0) { - var currentId = id$1++; + var existId = idMap.get(value); + var currentId = existId || id$1++; valueMap.set(currentId, value); + idMap.set(value, currentId); return { i: currentId, t: type, @@ -891,17 +894,10 @@ }; var getNodeWithCache = function (value, type, deep) { if (deep === void 0) { deep = 3; } - var cache = cacheMap.get(value); - if (cache) { - // check circular reference - if (loadById) { - return { - t: type, - n: "".concat(cache.n || cache.t, " (Circular Reference)"), - c: true, - v: cache.v, - e: true, - }; + if (loadById) { + var cache = cacheMap.get(value); + if (cache) { + return __assign(__assign({}, cache), { c: true }); } } var v = getTargetNode(value, type, deep); diff --git a/chrome/public/bundle/proxy.js b/chrome/public/bundle/proxy.js index f5e122a..fa1e03d 100644 --- a/chrome/public/bundle/proxy.js +++ b/chrome/public/bundle/proxy.js @@ -719,6 +719,7 @@ var id$1 = 1; var loadById = false; var valueMap = new Map(); + var idMap = new Map(); var cacheMap = new WeakMap(); var getType = function (value) { if (isInBrowser && value && value instanceof Element) { @@ -749,8 +750,10 @@ if (deep === void 0) { deep = 3; } // full deep to load if (deep === 0) { - var currentId = id$1++; + var existId = idMap.get(value); + var currentId = existId || id$1++; valueMap.set(currentId, value); + idMap.set(value, currentId); return { i: currentId, t: type, @@ -820,17 +823,10 @@ }; var getNodeWithCache = function (value, type, deep) { if (deep === void 0) { deep = 3; } - var cache = cacheMap.get(value); - if (cache) { - // check circular reference - if (loadById) { - return { - t: type, - n: "".concat(cache.n || cache.t, " (Circular Reference)"), - c: true, - v: cache.v, - e: true, - }; + if (loadById) { + var cache = cacheMap.get(value); + if (cache) { + return __assign(__assign({}, cache), { c: true }); } } var v = getTargetNode(value, type, deep); diff --git a/chrome/public/bundle/service-worker.js b/chrome/public/bundle/service-worker.js index dab62fd..f23095d 100644 --- a/chrome/public/bundle/service-worker.js +++ b/chrome/public/bundle/service-worker.js @@ -719,6 +719,7 @@ var id$1 = 1; var loadById = false; var valueMap = new Map(); + var idMap = new Map(); var cacheMap = new WeakMap(); var getType = function (value) { if (isInBrowser && value && value instanceof Element) { @@ -749,8 +750,10 @@ if (deep === void 0) { deep = 3; } // full deep to load if (deep === 0) { - var currentId = id$1++; + var existId = idMap.get(value); + var currentId = existId || id$1++; valueMap.set(currentId, value); + idMap.set(value, currentId); return { i: currentId, t: type, @@ -820,17 +823,10 @@ }; var getNodeWithCache = function (value, type, deep) { if (deep === void 0) { deep = 3; } - var cache = cacheMap.get(value); - if (cache) { - // check circular reference - if (loadById) { - return { - t: type, - n: "".concat(cache.n || cache.t, " (Circular Reference)"), - c: true, - v: cache.v, - e: true, - }; + if (loadById) { + var cache = cacheMap.get(value); + if (cache) { + return __assign(__assign({}, cache), { c: true }); } } var v = getTargetNode(value, type, deep); diff --git a/chrome/src/components/HookView.tsx b/chrome/src/components/HookView.tsx index 55d1901..db6769f 100644 --- a/chrome/src/components/HookView.tsx +++ b/chrome/src/components/HookView.tsx @@ -62,7 +62,7 @@ export const ValueViewTree = ({ name, item, prefix }: { name: string; item: HOOK const t = chunkData?.t ?? item?.t; - const isCircular = chunkData?.c ?? item?.c; + const isCache = chunkData?.c ?? item?.c; const text = useMemo(() => { if (n) { @@ -119,7 +119,7 @@ export const ValueViewTree = ({ name, item, prefix }: { name: string; item: HOOK {name}: {data ? text : } - {(isCircular ? expand : true) && ( + {(isCache ? expand : true) && (
{data ? ( Array.isArray(data) ? ( diff --git a/chrome/src/hooks/useDetailNode.ts b/chrome/src/hooks/useDetailNode.ts index 4218cb4..7d408c2 100644 --- a/chrome/src/hooks/useDetailNode.ts +++ b/chrome/src/hooks/useDetailNode.ts @@ -14,6 +14,10 @@ export const useDetailNode = createState(() => ({ nodes: [], loading: false, err s.nodes = list; }, + delNode: (id: string) => { + s.nodes = s.nodes.filter((i) => i.i !== id); + }, + setLoading: (loading: boolean) => { s.loading = loading; }, diff --git a/chrome/src/hooks/useTreeNode.ts b/chrome/src/hooks/useTreeNode.ts index 3a4b2f7..8d60b7b 100644 --- a/chrome/src/hooks/useTreeNode.ts +++ b/chrome/src/hooks/useTreeNode.ts @@ -5,6 +5,12 @@ import { isServer } from "@/utils/isServer"; import { flattenNode } from "@/utils/node"; import { useAppTree } from "./useAppTree"; +import { useChunk } from "./useChunk"; +import { useDetailNode } from "./useDetailNode"; + +const clearChunk = useChunk.getActions().clear; + +const delNode = useDetailNode.getActions().delNode; export const useTreeNode = createState( () => @@ -40,7 +46,13 @@ export const useTreeNode = createState( } }, forceReload: () => { - if (s.select) s.force++; + if (s.select) { + s.force++; + + delNode(s.select); + } + + clearChunk(); }, updateSelectList, setHover: (node: string | null) => { diff --git a/packages/core/src/data.ts b/packages/core/src/data.ts index 8abf136..baaa156 100644 --- a/packages/core/src/data.ts +++ b/packages/core/src/data.ts @@ -31,7 +31,7 @@ export type NodeValue = { e: boolean; // loaded l?: boolean; - // circular + // cache c?: boolean; // name n?: string; @@ -47,6 +47,8 @@ let loadById = false; const valueMap = new Map(); +const idMap = new Map(); + let cacheMap = new WeakMap(); const getType = (value: any): NodeValue["t"] => { @@ -85,8 +87,14 @@ const isObject = (value: NodeValue["t"]) => { const getTargetNode = (value: any, type: NodeValue["t"], deep = 3): NodeValue => { // full deep to load if (deep === 0) { - const currentId = id++; + const existId = idMap.get(value); + + const currentId = existId || id++; + valueMap.set(currentId, value); + + idMap.set(value, currentId); + return { i: currentId, t: type, @@ -148,18 +156,13 @@ const getTargetNode = (value: any, type: NodeValue["t"], deep = 3): NodeValue => }; const getNodeWithCache = (value: any, type: NodeValue["t"], deep = 3): NodeValue => { - const cache = cacheMap.get(value); - - if (cache) { - // check circular reference - if (loadById) { + if (loadById) { + const cache = cacheMap.get(value); + if (cache) { return { - t: type, - n: `${cache.n || cache.t} (Circular Reference)`, + ...cache, c: true, - v: cache.v, - e: true, - }; + } } }