From 89d2fcb81e8beb41c98e9a62263a0360519ef566 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 25 Aug 2025 11:01:12 +0300 Subject: [PATCH] refactor(react): add debug information for devtools --- apps/client/src/widgets/react/hooks.tsx | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index b4059ebfe..483f826dd 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -1,4 +1,4 @@ -import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks"; +import { useCallback, useContext, useDebugValue, useEffect, useMemo, useRef, useState } from "preact/hooks"; import { EventData, EventNames } from "../../components/app_context"; import { ParentComponent } from "./react_utils"; import SpacedUpdate from "../../services/spaced_update"; @@ -18,12 +18,14 @@ import { CSSProperties } from "preact/compat"; export function useTriliumEvent(eventName: T, handler: (data: EventData) => void) { const parentComponent = useContext(ParentComponent)!; parentComponent.registerHandler(eventName, handler); + useDebugValue(eventName); return (() => parentComponent.removeHandler(eventName, handler)); } export function useTriliumEvents(eventNames: T[], handler: (data: EventData, eventName: T) => void) { const parentComponent = useContext(ParentComponent)!; const handlers: ({ eventName: T, callback: (data: EventData) => void })[] = []; + useDebugValue(() => eventNames.join(", ")); for (const eventName of eventNames) { handlers.push({ eventName, callback: (data) => { @@ -98,6 +100,8 @@ export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [st } }, [ name ])); + useDebugValue(name); + return [ value, wrappedSetValue @@ -113,6 +117,7 @@ export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [st */ export function useTriliumOptionBool(name: OptionNames, needsRefresh?: boolean): [boolean, (newValue: boolean) => Promise] { const [ value, setValue ] = useTriliumOption(name, needsRefresh); + useDebugValue(name); return [ (value === "true"), (newValue) => setValue(newValue ? "true" : "false") @@ -128,6 +133,7 @@ export function useTriliumOptionBool(name: OptionNames, needsRefresh?: boolean): */ export function useTriliumOptionInt(name: OptionNames): [number, (newValue: number) => Promise] { const [ value, setValue ] = useTriliumOption(name); + useDebugValue(name); return [ (parseInt(value, 10)), (newValue) => setValue(newValue) @@ -142,6 +148,7 @@ export function useTriliumOptionInt(name: OptionNames): [number, (newValue: numb */ export function useTriliumOptionJson(name: OptionNames): [ T, (newValue: T) => Promise ] { const [ value, setValue ] = useTriliumOption(name); + useDebugValue(name); return [ (JSON.parse(value) as T), (newValue => setValue(JSON.stringify(newValue))) @@ -160,6 +167,8 @@ export function useTriliumOptions(...names: T[]) { values[name] = options.get(name); } + useDebugValue(() => names.join(", ")); + return [ values as Record, options.saveMany @@ -205,6 +214,8 @@ export function useNoteContext() { useTriliumEvent("frocaReloaded", () => { setNote(noteContext?.note); }); + + useDebugValue(() => `notePath=${notePath}, ntxId=${noteContext?.ntxId}`); const parentComponent = useContext(ParentComponent) as ReactWrappedWidget; @@ -248,6 +259,7 @@ export function useNoteProperty(note: FNote | null | unde } }); + useDebugValue(property); return note[property]; } @@ -269,6 +281,8 @@ export function useNoteRelation(note: FNote | undefined | null, relationName: st } }, [note]); + useDebugValue(relationName); + return [ relationValue, setter @@ -304,6 +318,8 @@ export function useNoteLabel(note: FNote | undefined | null, labelName: string): } }, [note]); + useDebugValue(labelName); + return [ labelValue, setter @@ -333,6 +349,8 @@ export function useNoteLabelBoolean(note: FNote | undefined | null, labelName: s } }, [note]); + useDebugValue(labelName); + return [ labelValue, setter ] as const; } @@ -354,6 +372,8 @@ export function useNoteBlob(note: FNote | null | undefined): [ FBlob | null | un } }); + useDebugValue(note.noteId); + return [ blob ] as const; } @@ -396,6 +416,8 @@ export function useLegacyWidget(widgetFactory: () => T, { } }, [ noteContext ]); + useDebugValue(widget); + return [
, widget ] } @@ -479,6 +501,8 @@ export function useTooltip(elRef: RefObject, config: Partial