@trackunit/react-components 3.8.1 → 3.8.2-alpha-775ca1816d6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,62 +0,0 @@
1
- type UseMigrateLegacySearchParamOptions<TState> = {
2
- readonly key: string;
3
- readonly enabled: boolean;
4
- /**
5
- * Pure decoder for the raw search-param string. Should not throw — return
6
- * `undefined` when the input can't be decoded.
7
- */
8
- readonly decode: (rawSearchValue: string) => unknown;
9
- /**
10
- * Optional transform applied to the decoded payload before validation
11
- * (mirrors `usePersistedState`'s `fromUrlValue`).
12
- */
13
- readonly fromUrlValue?: (decoded: unknown) => unknown;
14
- /**
15
- * Schema validator. Return the parsed state on success, `undefined`
16
- * otherwise.
17
- */
18
- readonly validate: (raw: unknown) => TState | undefined;
19
- /**
20
- * When `true`, the hash already carries a valid value for this key. The
21
- * hook still strips the legacy search param (so the URL is clean) but
22
- * does NOT fire `onMigrated` — the hash is canonical and we must not
23
- * stomp on it.
24
- */
25
- readonly hashAlreadyHasValue: boolean;
26
- /**
27
- * Called at most once when a valid legacy search-param value is found
28
- * and the hash is currently empty. Pipe through your normal
29
- * `persistState` so the value ends up in both the hash and localStorage.
30
- */
31
- readonly onMigrated: (state: TState) => void;
32
- };
33
- /**
34
- * One-shot migration: if the URL still carries a legacy `?<key>=...`
35
- * search param from before this hook moved table-style state to the
36
- * fragment, decode it, hand it to the caller via `onMigrated`, then strip
37
- * the search param via a `replace` navigation so back/forward history
38
- * isn't polluted.
39
- *
40
- * Invariants:
41
- * - The strip navigation fires at most once per mount (guarded by
42
- * `hasStrippedRef`) so we don't loop on the navigation we ourselves
43
- * triggered.
44
- * - `onMigrated` is also fired at most once per mount (guarded by
45
- * `hasMigratedRef`), but its gating is independent of the strip:
46
- * if `hashAlreadyHasValue` flips `true → false` after the strip
47
- * (e.g. an external actor clears the canonical hash mid-mount), the
48
- * next render still gets a chance to migrate the legacy value into
49
- * the hash. Conflating the two flags would have permanently lost
50
- * the legacy state in that race.
51
- * - Never throws — a decode/validate failure silently drops the value
52
- * and still strips the search param. The legacy key is owned by this
53
- * codebase's persistence convention (camelCase + `Tp` suffix), so
54
- * stripping unparseable values cannot destroy third-party data.
55
- * - When `hashAlreadyHasValue` is `true` the hash wins: the search
56
- * param is stripped but `onMigrated` is not fired.
57
- * - The `location.hash` is preserved verbatim across the strip
58
- * navigation so any concurrent hash content (including a freshly
59
- * written value) survives the cleanup.
60
- */
61
- export declare const useMigrateLegacySearchParam: <TState>({ key, enabled, decode, fromUrlValue, validate, hashAlreadyHasValue, onMigrated, }: UseMigrateLegacySearchParamOptions<TState>) => void;
62
- export {};