From c67d94c56e154be4b2cf91572cdc2d8d2da7f8e4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 11 Mar 2023 18:19:38 -0300 Subject: fix: #7753 --- packages/web-util/src/components/utils.ts | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'packages/web-util') diff --git a/packages/web-util/src/components/utils.ts b/packages/web-util/src/components/utils.ts index 71824e14f..34693f7d7 100644 --- a/packages/web-util/src/components/utils.ts +++ b/packages/web-util/src/components/utils.ts @@ -34,3 +34,50 @@ export function compose( return h(); }; } + +/** + * + * @param obj VNode + * @returns + */ +export function saveVNodeForInspection(obj: T): T { + // @ts-ignore + window["showVNodeInfo"] = function showVNodeInfo() { + inspect(obj); + }; + return obj; +} +function inspect(obj: any) { + if (!obj) return; + if (obj.__c && obj.__c.__H) { + const componentName = obj.__c.constructor.name; + const hookState = obj.__c.__H; + const stateList = hookState.__ as Array; + console.log("==============", componentName); + stateList.forEach((hook) => { + const { __: value, c: context, __h: factory, __H: args } = hook; + if (typeof context !== "undefined") { + const { __c: contextId } = context; + console.log("context:", contextId, hook); + } else if (typeof factory === "function") { + console.log("memo:", value, "deps:", args); + } else if (typeof value === "function") { + const effectName = value.name; + console.log("effect:", effectName, "deps:", args); + } else if (typeof value.current !== "undefined") { + const ref = value.current; + console.log("ref:", ref instanceof Element ? ref.outerHTML : ref); + } else if (value instanceof Array) { + console.log("state:", value[0]); + } else { + console.log(hook); + } + }); + } + const children = obj.__k; + if (children instanceof Array) { + children.forEach((e) => inspect(e)); + } else { + inspect(children); + } +} -- cgit v1.2.3