Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client): give every `useRef` an initial value under Preact 11
Elian Doran92b657e6a0a3
diff --git a/apps/client/src/widgets/NoteDetail.tsx b/apps/client/src/widgets/NoteDetail.tsxindex 6478cf9af8..35963747e9 100644--- a/apps/client/src/widgets/NoteDetail.tsx+++ b/apps/client/src/widgets/NoteDetail.tsx@@ -256,7 +256,7 @@ export default function NoteDetail() {* `isReady` turns true. A request made while ready is left to the widgets that already received it.*/export function useDeferredDetailFocus(isReady: boolean, replay: (data: EventData<"focusOnDetail">) => void) {- const pendingRef = useRef<EventData<"focusOnDetail">>();+ const pendingRef = useRef<EventData<"focusOnDetail"> | undefined>(undefined);const replayRef = useRef(replay);replayRef.current = replay;diff --git a/apps/client/src/widgets/attribute_widgets/label_value_input.tsx b/apps/client/src/widgets/attribute_widgets/label_value_input.tsxindex 63281bb244..ce18b8cc68 100644--- a/apps/client/src/widgets/attribute_widgets/label_value_input.tsx+++ b/apps/client/src/widgets/attribute_widgets/label_value_input.tsx@@ -297,7 +297,7 @@ export function getTypedInputForLabel(labelType: LabelType | undefined): LabelTy* memory. An empty `name` returns no suggestions, since `attribute-values/` matches no route.*/export function useLabelValueSuggestions(name: string) {- const known = useRef<{ name: string; values: string[] }>();+ const known = useRef<{ name: string; values: string[] } | undefined>(undefined);return useCallback(async (query: string) => {if (!name.trim()) {diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsxindex ecdb5c607a..28064916c1 100644--- a/apps/client/src/widgets/collections/NoteList.tsx+++ b/apps/client/src/widgets/collections/NoteList.tsx@@ -273,7 +273,7 @@ export function useViewModeConfig<T extends object>(note: FNote | null | undefinstoreFn: (data: T) => void;note: FNote;}>();- const storageRef = useRef<{ storage: ViewModeStorage<T>, storeFn: (data: T) => void, note: FNote }>();+ const storageRef = useRef<{ storage: ViewModeStorage<T>, storeFn: (data: T) => void, note: FNote } | undefined>(undefined);useEffect(() => {if (!note || !viewType) return;diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 0760e2ab5e..3371359688 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -248,7 +248,7 @@ export default function Column({// Cards slide to follow the drop gap opening and closing. Measured only when the column's own// cards have changed: reading one position costs a layout of the whole board, and anything// else that redraws it would have every column read one per card.- const measured = useRef<unknown>();+ const measured = useRef<unknown>(undefined);const cardsChanged = measured.current !== columnItems;measured.current = columnItems;useFlip(contentRef, {diff --git a/apps/client/src/widgets/collections/board/group_by.tsx b/apps/client/src/widgets/collections/board/group_by.tsxindex 993977303e..9ac918993b 100644--- a/apps/client/src/widgets/collections/board/group_by.tsx+++ b/apps/client/src/widgets/collections/board/group_by.tsx@@ -51,7 +51,7 @@ export default function BoardGroupBy({ note, options, current, onSelect }: {}) {const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);/** The definition the editor last reported, which {@link save} writes. */- const edited = useRef<Attribute>();+ const edited = useRef<Attribute | undefined>(undefined);const selected = options.find(option => option.value === current);const create = useCallback((event: MouseEvent) => {diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 03991f82b2..9bea19c056 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -523,7 +523,7 @@ export default function BoardView({// again: a new object would be a new prop on every card, and `memo` would then redraw all of// them for a move that touched one. Another board takes a new one, since this instance is// reused across boards and the api holds that board's record of the writes in flight.- const apiRef = useRef<{ board: string, api: Api }>();+ const apiRef = useRef<{ board: string, api: Api } | undefined>(undefined);const persistFilterQuery = useCallback((query: string) => apiRef.current?.api.setFilterQuery(query), []);const filter = useCollectionFilter(parentNote, {@@ -718,7 +718,9 @@ export default function BoardView({*/const [ releasedCollapse, setReleasedCollapse ] = useState<ReadonlyMap<string, boolean>>();/** What the last unheld render drew, which a hold keeps drawing. */- const drawnCollapse = useRef<{ collapse: ReadonlyMap<string, boolean>, cards?: ColumnMap }>();+ const drawnCollapse = useRef<+ { collapse: ReadonlyMap<string, boolean>, cards?: ColumnMap } | undefined+ >(undefined);const isCollapseHeld = releasedCollapse !== targetCollapse&& drawnCollapse.current?.cards !== undefined && drawnCollapse.current.cards !== byColumn&& sameColumns(drawnCollapse.current.collapse, targetCollapse)@@ -841,7 +843,7 @@ export default function BoardView({// comparison. A column changing width hides or shows its own cards and moves no card inside// any other, so there is nothing for any column to measure while it is happening.const columnResizingUntil = useRef(0);- const columnWidths = useRef<string>();+ const columnWidths = useRef<string | undefined>(undefined);const widths = shownColumns.map(column => collapsedColumns.get(column)&& column !== activeColumn && !isPeekingAll ? "1" : "0")@@ -1198,7 +1200,7 @@ export default function BoardView({* Let go a frame later than the one that draws it, a frame's callbacks running before the* styles it paints are worked out.*/- const stillFor = useRef<number>();+ const stillFor = useRef<number | undefined>(undefined);const holdStill = useCallback(() => {const container = containerRef.current;container?.classList.add("board-still");@@ -1906,9 +1908,9 @@ export function TitleEditor({}), []);/** Whether the field has already saved, for one that keeps what it saved standing. */const hasHandedOver = useRef(false);- const held = useRef<number>();+ const held = useRef<number | undefined>(undefined);/** Where on the screen the finger went down, against which a scroll is told from a hold. */- const heldFrom = useRef<{ x: number, y: number }>();+ const heldFrom = useRef<{ x: number, y: number } | undefined>(undefined);/** Whether the menu was opened by a hold, whose press ends in a click the menu must survive. */const openedByHold = useRef(false);diff --git a/apps/client/src/widgets/collections/collection_filter.tsx b/apps/client/src/widgets/collections/collection_filter.tsxindex fa91fa59ba..0a8c833c65 100644--- a/apps/client/src/widgets/collections/collection_filter.tsx+++ b/apps/client/src/widgets/collections/collection_filter.tsx@@ -72,7 +72,7 @@ export function useCollectionFilter(note: FNote, {// A run resolves on the server, so an older one can land after a newer one. Only the latest// run sets the result.const runSeqRef = useRef(0);- const rerunTimerRef = useRef<number>();+ const rerunTimerRef = useRef<number | undefined>(undefined);const previousNoteIdRef = useRef(note.noteId);const collectionSet = useMemo(() => new Set(collectionNoteIds), [ collectionNoteIds ]);const collectionSetRef = useRef(collectionSet);@@ -194,7 +194,7 @@ export function CollectionFilterInput({ filter, placeholder }: {placeholder?: string;}) {const [ typed, setTyped ] = useState(filter.query);- const editorRef = useRef<FieldEditor>();+ const editorRef = useRef<FieldEditor | undefined>(undefined);const { noteContext } = useNoteContext();// Adopt a query submitted elsewhere, or the stored one arriving on mount.diff --git a/apps/client/src/widgets/collections/geomap/Markers.tsx b/apps/client/src/widgets/collections/geomap/Markers.tsxindex 6fac1fd32a..19332497bb 100644--- a/apps/client/src/widgets/collections/geomap/Markers.tsx+++ b/apps/client/src/widgets/collections/geomap/Markers.tsx@@ -157,7 +157,7 @@ export default function Markers({ notes, hideLabels, isDarkTheme, clustered, placonst styleLoaded = useContext(MapStyleLoaded);// The markers last built, kept where both effects can reach them: the layer has to be able to// fill itself again the moment it is rebuilt, without waiting on a fresh build.- const markerData = useRef<Awaited<ReturnType<typeof buildMarkerData>>>();+ const markerData = useRef<Awaited<ReturnType<typeof buildMarkerData>> | undefined>(undefined);// How the titles are to be drawn, read rather than depended on: `install` is what builds the// layer, so a version of it per look would take the layer down and every marker with it for// what is two paint properties and a layout one. Only a layer being added fresh reads this —diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex 7dc64f8689..17aaf646bd 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -103,10 +103,10 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM// Which pick the map stands on, so a boundary arriving after a later one is dropped rather than// drawn around whatever took its place.const latestPlacePick = useRef(0);- const outlineTimer = useRef<ReturnType<typeof setTimeout>>();+ const outlineTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);// Gives up a boundary lookup already under way, which hands back its place in the geocoder's// request queue: the next search would otherwise wait out a boundary nobody is looking at.- const outlineRequest = useRef<AbortController>();+ const outlineRequest = useRef<AbortController | undefined>(undefined);// Held still between renders: the pin's layer is rebuilt whenever it is handed a different one,// and an array literal is different every time (see PlaceMarker).const placeCenter = useMemo<[number, number] | null>(diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsxindex 490597f8ba..316d38c697 100644--- a/apps/client/src/widgets/collections/geomap/map.tsx+++ b/apps/client/src/widgets/collections/geomap/map.tsx@@ -144,10 +144,10 @@ export default function Map({ coordinates, zoom, layerData, viewportChanged, chiconst [ map, setMap ] = useState<MapLibreGLMap | null>(null);const containerRef = useSyncedRef<HTMLDivElement>(_containerRef);- useImperativeHandle(apiRef ?? null, () => map);+ useImperativeHandle<MapLibreGLMap | null, MapLibreGLMap | null>(apiRef ?? null, () => map);// What the style this map was last given was made of, which is how the sources and layers on it// that are its own are told from the ones a child added. See `keepAdditions`.- const appliedStyle = useRef<StyleContents>();+ const appliedStyle = useRef<StyleContents | undefined>(undefined);// Whether there is no map to be had here at all — see the catch below.const [ unsupported, setUnsupported ] = useState(false);// See MapStyleLoaded.diff --git a/apps/client/src/widgets/collections/table/col_editing.ts b/apps/client/src/widgets/collections/table/col_editing.tsindex c54b300d1c..301167459a 100644--- a/apps/client/src/widgets/collections/table/col_editing.ts+++ b/apps/client/src/widgets/collections/table/col_editing.ts@@ -14,9 +14,9 @@ import { executeBulkActions } from "../../../services/bulk_action";export default function useColTableEditing(api: RefObject<Tabulator | null>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote) {- const existingAttributeToEdit = useRef<Attribute>();- const newAttribute = useRef<Attribute>();- const newAttributePosition = useRef<number>();+ const existingAttributeToEdit = useRef<Attribute | undefined>(undefined);+ const newAttribute = useRef<Attribute | undefined>(undefined);+ const newAttributePosition = useRef<number | undefined>(undefined);useLegacyImperativeHandlers({addNewTableColumnCommand({ referenceColumn, columnToEdit, direction, type }: EventData<"addNewTableColumn">) {diff --git a/apps/client/src/widgets/dialogs/item_picker.tsx b/apps/client/src/widgets/dialogs/item_picker.tsxindex 19aaba4bea..250a515d81 100644--- a/apps/client/src/widgets/dialogs/item_picker.tsx+++ b/apps/client/src/widgets/dialogs/item_picker.tsx@@ -52,7 +52,7 @@ const DEBOUNCE_MS = 150;* `dialog.pickSingleItem()`.*/export default function ItemPickerDialog() {- const opts = useRef<ItemPickerDialogOptions>();+ const opts = useRef<ItemPickerDialogOptions | undefined>(undefined);/** The item picked, reported in `onHidden` rather than while the dialog is closing. */const picked = useRef<PickerItem | null>(null);const searchRef = useRef<HTMLInputElement>(null);diff --git a/apps/client/src/widgets/dialogs/note_picker.tsx b/apps/client/src/widgets/dialogs/note_picker.tsxindex d2b913a684..fa687ed79e 100644--- a/apps/client/src/widgets/dialogs/note_picker.tsx+++ b/apps/client/src/widgets/dialogs/note_picker.tsx@@ -28,7 +28,7 @@ export interface NotePickerDialogOptions {* answer into a promise.*/export default function NotePickerDialog() {- const opts = useRef<NotePickerDialogOptions>();+ const opts = useRef<NotePickerDialogOptions | undefined>(undefined);const autocompleteRef = useRef<NoteAutocompleteHandle>(null);const [ suggestion, setSuggestion ] = useState<Suggestion | null>(null);const [ shown, setShown ] = useState(false);diff --git a/apps/client/src/widgets/dialogs/print_preview.tsx b/apps/client/src/widgets/dialogs/print_preview.tsxindex e1407a3e6d..7039ba7481 100644--- a/apps/client/src/widgets/dialogs/print_preview.tsx+++ b/apps/client/src/widgets/dialogs/print_preview.tsx@@ -98,9 +98,9 @@ export default function PrintPreviewDialog() {const [note, setNote] = useState<FNote>();const [loading, setLoading] = useState(false);const [error, setError] = useState<string>();- const bufferRef = useRef<Uint8Array>();+ const bufferRef = useRef<Uint8Array | undefined>(undefined);const notePathRef = useRef("");- const pdfUrlRef = useRef<string>();+ const pdfUrlRef = useRef<string | undefined>(undefined);const requestIdRef = useRef(0);diff --git a/apps/client/src/widgets/dialogs/prompt.tsx b/apps/client/src/widgets/dialogs/prompt.tsxindex b818f4d891..696eb11518 100644--- a/apps/client/src/widgets/dialogs/prompt.tsx+++ b/apps/client/src/widgets/dialogs/prompt.tsx@@ -31,7 +31,7 @@ export default function PromptDialog() {const formRef = useRef<HTMLFormElement>(null);const labelRef = useRef<HTMLLabelElement>(null);const answerRef = useRef<HTMLInputElement>(null);- const opts = useRef<PromptDialogOptions>();+ const opts = useRef<PromptDialogOptions | undefined>(undefined);const [ value, setValue ] = useState("");const [ shown, setShown ] = useState(false);const submitValue = useRef<string>(null);diff --git a/apps/client/src/widgets/launch_bar/CalendarWidget.tsx b/apps/client/src/widgets/launch_bar/CalendarWidget.tsxindex 523c064d51..00b89d7e0b 100644--- a/apps/client/src/widgets/launch_bar/CalendarWidget.tsx+++ b/apps/client/src/widgets/launch_bar/CalendarWidget.tsx@@ -37,7 +37,7 @@ export default function CalendarWidget({ launcherNote }: LauncherNoteProps) {const dropdownRef = useRef<DropdownHandle>(null);const [ enableWeekNotes, setEnableWeekNotes ] = useState(false);const [ weekNotes, setWeekNotes ] = useState<string[]>([]);- const calendarRootRef = useRef<FNote>();+ const calendarRootRef = useRef<FNote | undefined>(undefined);async function checkEnableWeekNotes() {if (!calendarRootRef.current) {diff --git a/apps/client/src/widgets/note_map/NoteMap.tsx b/apps/client/src/widgets/note_map/NoteMap.tsxindex f82fe096ad..2464ffa316 100644--- a/apps/client/src/widgets/note_map/NoteMap.tsx+++ b/apps/client/src/widgets/note_map/NoteMap.tsx@@ -35,7 +35,8 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {const [ mapType, setMapType ] = useMapType(note, widgetMode);const [ mapRootIdLabel ] = useNoteLabel(note, "mapRootNoteId");- const graphRef = useRef<ForceGraph<NoteMapNodeObject, NoteMapLinkObject>>();+ const graphRef =+ useRef<ForceGraph<NoteMapNodeObject, NoteMapLinkObject> | undefined>(undefined);// Everything the map is drawn in is settled when it is built — the colour of a note of each type,// the colour its title is written in, the shadow under it — so a change of theme calls for it to// be built again. The hook answers a theme being chosen and, for the themes that follow the@@ -46,7 +47,7 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {const [ linkDistance, setLinkDistance ] = useState(40);const [ tooManyNotes, setTooManyNotes ] = useState<number | null>(null);const [ bypassLimit, setBypassLimit ] = useState(false);- const notesAndRelationsRef = useRef<NotesAndRelationsData>();+ const notesAndRelationsRef = useRef<NotesAndRelationsData | undefined>(undefined);const mapRootId = useMemo(() => {if (note.noteId && isRootedAtCurrentNote(widgetMode)) {diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsxindex 3b77d913eb..6e31893570 100644--- a/apps/client/src/widgets/note_title.tsx+++ b/apps/client/src/widgets/note_title.tsx@@ -57,7 +57,7 @@ export default function NoteTitleWidget(props: {className?: string}) {// Manage focus.const textBoxRef = useRef<HTMLInputElement>(null);- const isNewNote = useRef<boolean>();+ const isNewNote = useRef<boolean | undefined>(undefined);const pendingSelect = useRef<boolean>(false);// Re-apply selection when title changes if we have a pending select.diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsxindex 12725fb3fc..a57abadde6 100644--- a/apps/client/src/widgets/quick_search.tsx+++ b/apps/client/src/widgets/quick_search.tsx@@ -59,7 +59,7 @@ export default function QuickSearch() {const [ open, setOpen ] = useState(false);// Set while the keys move through the results; see `.tn-menu-keyboard` in Menu.css.const [ keyboardDriven, setKeyboardDriven ] = useState(false);- const editorRef = useRef<FieldEditor>();+ const editorRef = useRef<FieldEditor | undefined>(undefined);const boxRef = useRef<HTMLDivElement>(null);const popupRef = useRef<HTMLDivElement | null>(null);// Each search takes a number, so a slower earlier response cannot overwrite a later one.diff --git a/apps/client/src/widgets/react/FormAutocomplete.tsx b/apps/client/src/widgets/react/FormAutocomplete.tsxindex 706c5e3e39..771c969a85 100644--- a/apps/client/src/widgets/react/FormAutocomplete.tsx+++ b/apps/client/src/widgets/react/FormAutocomplete.tsx@@ -398,7 +398,7 @@ export function useAutocomplete<T>({ query, source, onPick, inputRef, disabled,const scrollToActive = useRef(false);// Where the pointer last moved over the list. Scrolling slides a row under a still pointer, and the// browser can report that as a move at the same spot, which is not the pointer choosing the row.- const lastPointer = useRef<{ x: number; y: number }>();+ const lastPointer = useRef<{ x: number; y: number } | undefined>(undefined);// Names the entries so the field can point at the highlighted one: focus stays in the box, so// that pointer is all a screen reader has to go on.const itemIdPrefix = useUniqueName("autocomplete-item");diff --git a/apps/client/src/widgets/react/FormTextBox.tsx b/apps/client/src/widgets/react/FormTextBox.tsxindex 696e425249..ab77725ebc 100644--- a/apps/client/src/widgets/react/FormTextBox.tsx+++ b/apps/client/src/widgets/react/FormTextBox.tsx@@ -41,7 +41,7 @@ export default function FormTextBox({ inputRef, className, type, currentValue, o// compat-using import, remaps `onChange` — in any casing — to the input event. Held in a ref so// the once-bound listener commits through the props of the render it fires in, not the one it// was bound in.- const commitNumber = useRef<() => void>();+ const commitNumber = useRef<(() => void) | undefined>(undefined);commitNumber.current = () => {const input = innerRef.current;if (!input) return;diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsxindex 2d46746a41..1911ffe77f 100644--- a/apps/client/src/widgets/react/Menu.tsx+++ b/apps/client/src/widgets/react/Menu.tsx@@ -86,7 +86,7 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,const [ active, setActiveRow ] = useState<ActiveRow>();const rows = useRef(new Map<string, RowEntry>()).current;/** The level whose first row becomes active once it has rendered, for a submenu a key opened. */- const pendingFirstRow = useRef<number>();+ const pendingFirstRow = useRef<number | undefined>(undefined);const typeahead = useRef({ text: "", timeout: 0 });/** Whether the keys moved the menu since the pointer last did. See `Menu.css`. */const [ keyboardDriven, setKeyboardDriven ] = useState(false);diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsxindex df6d5da42a..2bddd14327 100644--- a/apps/client/src/widgets/react/Modal.tsx+++ b/apps/client/src/widgets/react/Modal.tsx@@ -109,8 +109,8 @@ export interface ModalProps {export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus, sidebar, hideSidebarHeader, isFullPageOnMobile, ariaLabel }: ModalProps) {const modalRef = useSyncedRef<HTMLDivElement>(externalModalRef);- const modalInstanceRef = useRef<BootstrapModal>();- const elementToFocus = useRef<Element | null>();+ const modalInstanceRef = useRef<BootstrapModal | undefined>(undefined);+ const elementToFocus = useRef<Element | null | undefined>(undefined);/** Bootstrap writes classes of its own onto this element — `show` above all, which is what makesdiff --git a/apps/client/src/widgets/react/Popover.tsx b/apps/client/src/widgets/react/Popover.tsxindex 9c6db392bb..90456845fc 100644--- a/apps/client/src/widgets/react/Popover.tsx+++ b/apps/client/src/widgets/react/Popover.tsx@@ -67,7 +67,7 @@ export interface PopoverProps {export default function Popover({ getAnchorRect, placement, updateKey, className, keepOpenSelector, onDismiss, maximized, onPlaced, children }: PopoverProps) {const elRef = useRef<HTMLDivElement>(null);const arrowRef = useRef<HTMLDivElement>(null);- const updateRef = useRef<() => void>();+ const updateRef = useRef<(() => void) | undefined>(undefined);// In a ref, so the placement set up once reads the latest `getAnchorRect`. Setting it up again// on every render would reset the position mid-interaction.diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.tsxindex 2de53bf5d2..5922d8ef8e 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.tsx+++ b/apps/client/src/widgets/react/PromotedAttributesCard.tsx@@ -94,9 +94,9 @@ export default function PromotedAttributesCard({}const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);/** The definition the editor last reported, which `save` writes. */- const edited = useRef<Attribute>();+ const edited = useRef<Attribute | undefined>(undefined);/** The definition the editor was handed, which `save` compares against to spot a rename. */- const original = useRef<Attribute>();+ const original = useRef<Attribute | undefined>(undefined);// A definition created, renamed or deleted here arrives as an attribute change. Resolving// against the current list is what keeps the order of the rest.diff --git a/apps/client/src/widgets/react/SortableCard.tsx b/apps/client/src/widgets/react/SortableCard.tsxindex 0563249c65..0529636295 100644--- a/apps/client/src/widgets/react/SortableCard.tsx+++ b/apps/client/src/widgets/react/SortableCard.tsx@@ -122,9 +122,9 @@ export function SortableCard<T extends SortableItem>({const listRef = useRef<HTMLDivElement>(null);const adderRef = useRef<HTMLElement>(null);- const dragRef = useRef<Drag<T>>();+ const dragRef = useRef<Drag<T> | undefined>(undefined);/** A touch waiting out `TOUCH_HOLD_MS`, after which it becomes a drag. */- const holdRef = useRef<Hold>();+ const holdRef = useRef<Hold | undefined>(undefined);/** The last pointer position, needed when scrolling moves the list under a still pointer. */const pointerRef = useRef({ x: 0, y: 0 });/** The current `dragTo`, so the scroller can reposition the segment without a stale closure. */@@ -157,7 +157,7 @@ export function SortableCard<T extends SortableItem>({/** The entry just added, which grows and fades in. */const [ addedKey, setAddedKey ] = useState<string>();/** The segment to focus after the next render: moving an element drops its focus. */- const pendingFocus = useRef<string>();+ const pendingFocus = useRef<string | undefined>(undefined);const shown = draft ?? items;/** The current list, for a callback that resumes after an await. */diff --git a/apps/client/src/widgets/react/drag_pan.ts b/apps/client/src/widgets/react/drag_pan.tsindex bac4614928..682047942d 100644--- a/apps/client/src/widgets/react/drag_pan.ts+++ b/apps/client/src/widgets/react/drag_pan.ts@@ -43,7 +43,7 @@ export function useDragPan(ref: RefObject<HTMLElement | null>, options: DragPanOconst { canStart, disabled } = options;const [ isPannable, setPannable ] = useState(false);const [ isPanning, setPanning ] = useState(false);- const glideRef = useRef<number>();+ const glideRef = useRef<number | undefined>(undefined);// A ref holds no render of its own, so an effect keyed on one never hears the element arrive.// Containers drawn only once their content has loaded are the ordinary case, so the element isdiff --git a/apps/client/src/widgets/react/flip.ts b/apps/client/src/widgets/react/flip.tsindex 99e495df20..4f276be237 100644--- a/apps/client/src/widgets/react/flip.ts+++ b/apps/client/src/widgets/react/flip.ts@@ -66,7 +66,7 @@ export function useFlip(const drawn = useRef(false);/** Whether a growth is running, during which the children below it are already moving. */const settling = useRef(false);- const settled = useRef<number>();+ const settled = useRef<number | undefined>(undefined);const read = useCallback(() => {const places = new Map<Element, Place>();diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex d617df400b..9041cfeb5c 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -125,7 +125,7 @@ export function useEditorSpacedUpdate({ note, noteType, noteContext, getData, on// The note whose content is currently loaded in the editor. Editor instances are reused// across note switches, so until the new note's blob arrives the editor still holds the// previous note's content — content that must never be saved under the new noteId (#9614).- const loadedNoteIdRef = useRef<string>();+ const loadedNoteIdRef = useRef<string | undefined>(undefined);const prepare = useCallback(() => {if (!note || loadedNoteIdRef.current !== note.noteId) return undefined;@@ -154,7 +154,7 @@ export function useEditorSpacedUpdate({ note, noteType, noteContext, getData, onstateCallbackRef.current = stateCallback;}, [ stateCallback ]);- const spacedUpdateRef = useRef<SpacedUpdate<SavedData | undefined>>();+ const spacedUpdateRef = useRef<SpacedUpdate<SavedData | undefined> | undefined>(undefined);if (!spacedUpdateRef.current) {spacedUpdateRef.current = new SpacedUpdate<SavedData | undefined>({ key: note?.noteId ?? null, prepare, commit },@@ -231,7 +231,7 @@ export function useBlobEditorSpacedUpdate({ note, noteType, noteContext, getData// Same provenance guard as useEditorSpacedUpdate: never save content under a note it// was not loaded from (#9614).- const loadedNoteIdRef = useRef<string>();+ const loadedNoteIdRef = useRef<string | undefined>(undefined);const prepare = useCallback(() => {if (loadedNoteIdRef.current !== note.noteId) return undefined;@@ -257,7 +257,7 @@ export function useBlobEditorSpacedUpdate({ note, noteType, noteContext, getDatastateCallbackRef.current = stateCallback;}, [ stateCallback ]);- const spacedUpdateRef = useRef<SpacedUpdate<Blob | undefined>>();+ const spacedUpdateRef = useRef<SpacedUpdate<Blob | undefined> | undefined>(undefined);if (!spacedUpdateRef.current) {spacedUpdateRef.current = new SpacedUpdate<Blob | undefined>({ key: note.noteId, prepare, commit },@@ -1538,7 +1538,7 @@ const MAX_REGEX_MATCHES = 500;export function useImperativeSearchHighlighlighting(highlightedTokens: (string | HighlightedTokenInfo)[] | null | undefined) {- const mark = useRef<Mark>();+ const mark = useRef<Mark | undefined>(undefined);const tokenInfos = useMemo<HighlightedTokenInfo[] | null>(() => {if (!highlightedTokens?.length) return null;return highlightedTokens.map((token) => (typeof token === "string" ? { token, type: "plain" as const } : token));diff --git a/apps/client/src/widgets/react/scroll_fade.ts b/apps/client/src/widgets/react/scroll_fade.tsindex 5613ced480..d4953f8763 100644--- a/apps/client/src/widgets/react/scroll_fade.ts+++ b/apps/client/src/widgets/react/scroll_fade.ts@@ -54,7 +54,7 @@ export function useScrollFade(ref: RefObject<HTMLElement | null>, options: Scrol} = options;const [ fades, setFades ] = useState({ start: false, end: false });const [ overflow, setOverflow ] = useState(0);- const frameRef = useRef<number>();+ const frameRef = useRef<number | undefined>(undefined);const element = useTrackedElement(ref);diff --git a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx b/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsxindex c69c18b4dc..56a0d52b9c 100644--- a/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx+++ b/apps/client/src/widgets/ribbon/SearchDefinitionOptions.tsx@@ -159,7 +159,7 @@ function SearchStringOption({ note, refreshResults, error, ...restProps }: Searc}}, [ note, setSearchString ]);- const spacedUpdateRef = useRef<SpacedUpdate<string>>();+ const spacedUpdateRef = useRef<SpacedUpdate<string> | undefined>(undefined);if (!spacedUpdateRef.current) {spacedUpdateRef.current = new SpacedUpdate<string>({ key: note.noteId, prepare, commit }, 1000);}diff --git a/apps/client/src/widgets/ribbon/SearchStringEditor.tsx b/apps/client/src/widgets/ribbon/SearchStringEditor.tsxindex 8d88772184..3d6ebe2cd5 100644--- a/apps/client/src/widgets/ribbon/SearchStringEditor.tsx+++ b/apps/client/src/widgets/ribbon/SearchStringEditor.tsx@@ -78,7 +78,7 @@ const SINGLE_LINE_HINTS: ShortcutHintDefinition = [*/export default function SearchStringEditor({ currentValue, noteId, placeholder, ariaLabel, className, autoFocus, singleLine, extraShortcutHints, editorRef: exposedRef, onChange, onEnter, onArrowDown, onEscape }: SearchStringEditorProps) {const parentRef = useRef<HTMLDivElement>(null);- const editorRef = useRef<FieldEditor>();+ const editorRef = useRef<FieldEditor | undefined>(undefined);// The editor is built once, so it reaches the current props through a ref rather than// through the closure of the render that created it.const propsRef = useRef({ currentValue, onChange, onEnter, onArrowDown, onEscape });diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsxindex 921edd7e7f..25ac624f0e 100644--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx@@ -65,11 +65,11 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxIconst [isMenuOpen, setIsMenuOpen] = useState(false);const suppressNextOnHide = useRef(false);- const blinkTimeout = useRef<ReturnType<typeof setTimeout>>();- const lastSavedContent = useRef<string>();+ const blinkTimeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);+ const lastSavedContent = useRef<string | undefined>(undefined);const currentValueRef = useRef(currentValue);const wrapperRef = useRef<HTMLDivElement>(null);- const editorRef = useRef<CKEditorApi>();+ const editorRef = useRef<CKEditorApi | undefined>(undefined);// The editor outlives a switch to another note, so its `@` list reads the path as it opens.const notePathRef = useRef(notePath);notePathRef.current = notePath;diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsxindex 06837fe917..e99d348e6e 100644--- a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx@@ -28,7 +28,7 @@ export default function ShortcutHintsPanel() {// `undefined` means closed. Only ever set with a non-empty section list, so presence == open.const [ state, setState ] = useState<OpenState>();const panelRef = useRef<HTMLDivElement>(null);- const timerRef = useRef<number>();+ const timerRef = useRef<number | undefined>(undefined);// Kept in a ref so the outside-click handler always sees the current anchor without re-subscribing.const anchorRef = useRef<HTMLElement | null>(null);anchorRef.current = state?.anchor ?? null;diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex 729e4cd5f7..59bc137451 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -74,7 +74,7 @@ export default function AttributeList() {// Collected while rendering rather than in an effect, which would leave one frame listing the// attributes of the note navigated away from. The initial `undefined` is what collects the first.- const shownNoteId = useRef<string | null>();+ const shownNoteId = useRef<string | null | undefined>(undefined);if (shownNoteId.current !== (note?.noteId ?? null)) {// An attribute left open for editing — in the popup or in its own row — is closed by the// change of note, and closing keeps what was typed into it — as a press outside does — ratherdiff --git a/apps/client/src/widgets/type_widgets/canvas/persistence.ts b/apps/client/src/widgets/type_widgets/canvas/persistence.tsindex 01513f9ae5..794b4cd727 100644--- a/apps/client/src/widgets/type_widgets/canvas/persistence.ts+++ b/apps/client/src/widgets/type_widgets/canvas/persistence.ts@@ -62,7 +62,8 @@ export default function useCanvasPersistence(note: FNote, noteContext: NoteConte// loaded via `updateScene` in that window is wiped — and the wipe then looks like a// user edit and gets saved over the note (#10279). Excalidraw awaits this promise and// applies its value as part of that very reset, so the first load cannot be clobbered.- const initialDataRef = useRef<DeferredPromise<ExcalidrawInitialDataState | null>>();+ const initialDataRef =+ useRef<DeferredPromise<ExcalidrawInitialDataState | null> | undefined>(undefined);if (!initialDataRef.current) {initialDataRef.current = deferred<ExcalidrawInitialDataState | null>();}diff --git a/apps/client/src/widgets/type_widgets/code/CodeMirror.tsx b/apps/client/src/widgets/type_widgets/code/CodeMirror.tsxindex 1e17fc953c..469238e3db 100644--- a/apps/client/src/widgets/type_widgets/code/CodeMirror.tsx+++ b/apps/client/src/widgets/type_widgets/code/CodeMirror.tsx@@ -19,7 +19,7 @@ export interface CodeMirrorProps extends Omit<EditorConfig, "parent"> {export default function CodeMirror({ className, content, mime, editorRef: externalEditorRef, containerRef: externalContainerRef, onInitialized, lineWrapping, customRequestHandler, allowKeyboardSuggestions, ...extraOpts }: CodeMirrorProps) {const parentRef = useSyncedRef(externalContainerRef);- const codeEditorRef = useRef<VanillaCodeMirror>();+ const codeEditorRef = useRef<VanillaCodeMirror | undefined>(undefined);// Create CodeMirror instance.useEffect(() => {diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsxindex f43a2dedd9..d5284d1a11 100644--- a/apps/client/src/widgets/type_widgets/file/Video.tsx+++ b/apps/client/src/widgets/type_widgets/file/Video.tsx@@ -200,7 +200,7 @@ function useKeyboardShortcuts(videoRef: MutableRef<HTMLVideoElement | null>, wrafunction useAutoHideControls(videoRef: RefObject<HTMLVideoElement | null>, playing: boolean) {const [visible, setVisible] = useState(true);- const hideTimerRef = useRef<ReturnType<typeof setTimeout>>();+ const hideTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);const scheduleHide = useCallback(() => {clearTimeout(hideTimerRef.current);diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsxindex 8e5d9ca9a0..ebb9c1d9b3 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx@@ -87,8 +87,8 @@ export default function ChatInputBar({const [modalStep, setModalStep] = useState<ProviderStep | undefined>();const [modalOpen, setModalOpen] = useState(false);const [openToken, setOpenToken] = useState(0);- const editorApiRef = useRef<CKEditorApi>();- const editorInstanceRef = useRef<CKTextEditor>();+ const editorApiRef = useRef<CKEditorApi | undefined>(undefined);+ const editorInstanceRef = useRef<CKTextEditor | undefined>(undefined);const [ uiLanguage ] = useTriliumOption("locale");// CKEditor is the heaviest module the client has, and importing it statically here put it// on the startup critical path: the right panel mounts SidebarChat, which pulls this bar,diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.tsindex 4017d4f5d1..0ed94b5f6a 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts@@ -274,7 +274,7 @@ export function useLlmChat(// The reply-input editor, registered by ChatInputBar once its CKEditor has initialized. Held in a// ref so timeline actions (e.g. quoting a selection) can write into it without a render-order// dependency.- const inputEditorRef = useRef<InputEditorApi | undefined>();+ const inputEditorRef = useRef<InputEditorApi | undefined>(undefined);const isInputFocusPendingRef = useRef(false);const registerInputEditor = useCallback((api: InputEditorApi | undefined) => {inputEditorRef.current = api;diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsxindex cd59ed0331..859a99d34f 100644--- a/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsx+++ b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsx@@ -28,7 +28,7 @@ export default function NodeMemo({ selectionKey, memo, readOnly, onCommit }: {readOnly: boolean;onCommit(html: string): void;}) {- const apiRef = useRef<CKEditorApi>();+ const apiRef = useRef<CKEditorApi | undefined>(undefined);const editorRef = useRef<CKTextEditor>(null);const [ uiLanguage ] = useTriliumOption("locale");const html = toMemoHtml(memo);diff --git a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsxindex 94cd944f1f..31e59bbcfc 100644--- a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx+++ b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx@@ -15,7 +15,7 @@ export function JsPlumb({ className, props, children, containerRef: externalContonConnection?: (info: OnConnectionBindInfo, originalEvent: Event) => void;}) {const containerRef = useRef<HTMLDivElement>(null);- const jsPlumbRef = useRef<jsPlumbInstance>();+ const jsPlumbRef = useRef<jsPlumbInstance | undefined>(undefined);useEffect(() => {if (!containerRef.current) return;diff --git a/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx b/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsxindex d72f207376..25b5cd2646 100644--- a/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx+++ b/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx@@ -91,7 +91,7 @@ function useUniverLocale() {function SpreadsheetEditor({ note, noteContext, readOnly, locale }: TypeWidgetProps & { readOnly: boolean; locale: UniverLocale }) {const containerRef = useRef<HTMLDivElement>(null);- const apiRef = useRef<FUniver>();+ const apiRef = useRef<FUniver | undefined>(undefined);useInitializeSpreadsheet(containerRef, apiRef, readOnly, locale);useReleaseFillShortcuts(apiRef);diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsxindex dfc7f4b747..796a1f7057 100644--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx@@ -56,12 +56,12 @@ export default function EditableText({ note, parentComponent, ntxId, noteContextconst containerRef = useRef<HTMLDivElement>(null);const contentRef = useRef<string>("");/** The note `contentRef` holds the content of, so a restarted editor can be marked as holding it. */- const contentNoteIdRef = useRef<string>();- const pendingAttachmentChangesRef = useRef<PendingAttachmentChanges>();+ const contentNoteIdRef = useRef<string | undefined>(undefined);+ const pendingAttachmentChangesRef = useRef<PendingAttachmentChanges | undefined>(undefined);/** The attachment whose embed takes the focus when it renders next. */- const focusedAttachmentIdRef = useRef<string>();+ const focusedAttachmentIdRef = useRef<string | undefined>(undefined);const watchdogRef = useRef<EditorWatchdog>(null);- const stopWatchingEmbedsRef = useRef<() => void>();+ const stopWatchingEmbedsRef = useRef<(() => void) | undefined>(undefined);const editorApiRef = useRef<CKEditorApi>(null);/** The open icon picker request and its balloon container, or `null` when none is open. */const [ iconPickerRequest, setIconPickerRequest ] = useState<IconPickerOpts & { container: HTMLElement } | null>(null);