diff --git a/app/src/data/schema/SchemaManager.ts b/app/src/data/schema/SchemaManager.ts index b991c67..ab5fbda 100644 --- a/app/src/data/schema/SchemaManager.ts +++ b/app/src/data/schema/SchemaManager.ts @@ -333,7 +333,7 @@ export class SchemaManager { if (config.force) { try { - $console.log("[SchemaManager]", sql); + $console.debug("[SchemaManager]", sql); await qb.execute(); } catch (e) { throw new Error(`Failed to execute query: ${sql}: ${(e as any).message}`); diff --git a/app/src/ui/hooks/use-search.ts b/app/src/ui/hooks/use-search.ts index 915b201..012465d 100644 --- a/app/src/ui/hooks/use-search.ts +++ b/app/src/ui/hooks/use-search.ts @@ -2,7 +2,7 @@ import { decodeSearch, encodeSearch, mergeObject } from "core/utils"; import { isEqual, transform } from "lodash-es"; import { useLocation, useSearch as useWouterSearch } from "wouter"; import { type s, parse } from "core/object/schema"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; export type UseSearchOptions = { defaultValue?: Partial>; @@ -18,21 +18,24 @@ export function useSearch( const [value, setValue] = useState>( options?.defaultValue ?? ({} as any), ); - const _defaults = mergeObject( - // @ts-ignore - schema.template({ withOptional: true }), - options?.defaultValue ?? {}, - ); + + const defaults = useMemo(() => { + return mergeObject( + // @ts-ignore + schema.template({ withOptional: true }), + options?.defaultValue ?? {}, + ); + }, [JSON.stringify({ schema, dflt: options?.defaultValue })]); useEffect(() => { const initial = searchString.length > 0 ? decodeSearch(searchString) : (options?.defaultValue ?? {}); - const v = parse(schema, Object.assign({}, _defaults, initial)) as any; + const v = parse(schema, Object.assign({}, defaults, initial)) as any; setValue(v); }, [searchString, JSON.stringify(options?.defaultValue), location]); function set>>(update: Update): void { - const search = getWithoutDefaults(Object.assign({}, value, update), _defaults); + const search = getWithoutDefaults(Object.assign({}, value, update), defaults); const prepared = options?.beforeEncode?.(search) ?? search; const encoded = encodeSearch(prepared, { encode: false }); navigate(location + (encoded.length > 0 ? "?" + encoded : ""));