@tschk/moonshine-tanstack 0.4.4 → 0.4.49
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.
- package/README.md +9 -2
- package/package.json +3 -3
- package/src/navigation.ts +26 -11
package/README.md
CHANGED
|
@@ -57,13 +57,13 @@ own loader/RPC runtime, and are **not** provided:
|
|
|
57
57
|
plain string/record with no route-tree inference — `from` is accepted and
|
|
58
58
|
ignored, `strict` has no effect.
|
|
59
59
|
- **Data loading**: `loader`, `useLoaderData`, `useLoaderDeps`, `beforeLoad`,
|
|
60
|
-
`validateSearch`, `
|
|
60
|
+
`validateSearch`, `useMatch`,
|
|
61
61
|
`useMatches`, `useMatchRoute`, `Await`, `defer`, pending/error components.
|
|
62
62
|
- **Server functions**: `createServerFn`, `createMiddleware`,
|
|
63
63
|
`createStartHandler` — these depend on the build plugin's client/server
|
|
64
64
|
splitting. Use `createServerRoute` on a moonshine route instead.
|
|
65
65
|
- **Transitions/blocking**: `useBlocker`, `Block`, `isTransitioning`
|
|
66
|
-
(always `false`), `useRouterState().status` (
|
|
66
|
+
(always `false`), `useRouterState().status` (idle or pending for the opt-in data runtime),
|
|
67
67
|
`matches` (always empty).
|
|
68
68
|
- **History state hook**: navigation state is available in `location.state`;
|
|
69
69
|
there is no separate `useHistoryState` hook.
|
|
@@ -71,3 +71,10 @@ own loader/RPC runtime, and are **not** provided:
|
|
|
71
71
|
its scoped server snapshot.
|
|
72
72
|
|
|
73
73
|
See [Moonshine README](../../README.md).
|
|
74
|
+
|
|
75
|
+
`useRouter().invalidate()` now delegates to an explicitly supplied Moonshine
|
|
76
|
+
`createDataRouter` runtime from `@tschk/moonshine-router/data`. It returns a
|
|
77
|
+
promise and rejects for a navigation-only runtime. With a data runtime,
|
|
78
|
+
`useRouterState` reports pending/loading and loader errors remain in native data
|
|
79
|
+
state. This does not implement TanStack loader hooks, route caching, match
|
|
80
|
+
state or route-tree inference.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tschk/moonshine-tanstack",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.49",
|
|
4
4
|
"description": "TanStack Router / Start client API reimplemented on moonshine — drop @tanstack/react-router, keep the imports",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"./aliases": "./src/aliases.ts"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@tschk/moonshine": "^0.4.
|
|
20
|
-
"@tschk/moonshine-router": "^0.4.
|
|
19
|
+
"@tschk/moonshine": "^0.4.48",
|
|
20
|
+
"@tschk/moonshine-router": "^0.4.48"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"react": ">=18",
|
package/src/navigation.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* import { useNavigate, useRouterState } from "@tschk/moonshine-tanstack";
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
import { useCallback, useMemo } from "react";
|
|
10
|
+
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
11
11
|
import {
|
|
12
12
|
useNavigate as useMoonshineNavigate,
|
|
13
13
|
useParams as useMoonshineParams,
|
|
14
|
+
useRouter as useMoonshineRouter,
|
|
14
15
|
} from "@tschk/moonshine/router";
|
|
15
16
|
import {
|
|
16
17
|
buildHref,
|
|
@@ -31,7 +32,7 @@ export type RouterInstance = {
|
|
|
31
32
|
forward(): void;
|
|
32
33
|
go(delta: number): void;
|
|
33
34
|
};
|
|
34
|
-
invalidate(): void
|
|
35
|
+
invalidate(): Promise<void>;
|
|
35
36
|
state: { location: ParsedLocation };
|
|
36
37
|
};
|
|
37
38
|
|
|
@@ -54,6 +55,7 @@ export function useNavigate(): NavigateFn {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export function useRouter(): RouterInstance {
|
|
58
|
+
const runtime = useMoonshineRouter();
|
|
57
59
|
const location = useParsedLocation();
|
|
58
60
|
const go = useNavigate();
|
|
59
61
|
return useMemo(
|
|
@@ -67,36 +69,49 @@ export function useRouter(): RouterInstance {
|
|
|
67
69
|
forward: () => globalThis.history?.forward(),
|
|
68
70
|
go: (delta: number) => globalThis.history?.go(delta),
|
|
69
71
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
invalidate: async () => {
|
|
73
|
+
if (!runtime.invalidate)
|
|
74
|
+
throw new Error(
|
|
75
|
+
"Route invalidation requires an opt-in Moonshine data router",
|
|
76
|
+
);
|
|
77
|
+
await runtime.invalidate().catch(() => {});
|
|
78
|
+
},
|
|
73
79
|
state: { location },
|
|
74
80
|
}),
|
|
75
|
-
[go, location],
|
|
81
|
+
[go, location, runtime],
|
|
76
82
|
);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
export type RouterState = {
|
|
80
86
|
location: ParsedLocation;
|
|
81
|
-
status: "idle";
|
|
82
|
-
isLoading:
|
|
87
|
+
status: "idle" | "pending";
|
|
88
|
+
isLoading: boolean;
|
|
83
89
|
isTransitioning: false;
|
|
84
90
|
matches: never[];
|
|
85
91
|
};
|
|
86
92
|
|
|
93
|
+
const noop = () => {};
|
|
94
|
+
const subscribeEmpty = () => noop;
|
|
95
|
+
|
|
87
96
|
export function useRouterState<T = RouterState>(options?: {
|
|
88
97
|
select?: (state: RouterState) => T;
|
|
89
98
|
}): T {
|
|
90
99
|
const location = useParsedLocation();
|
|
100
|
+
const runtime = useMoonshineRouter();
|
|
101
|
+
const pending = useSyncExternalStore(
|
|
102
|
+
runtime.data?.subscribe ?? subscribeEmpty,
|
|
103
|
+
() => runtime.data?.peek().status === "pending",
|
|
104
|
+
() => runtime.data?.peek().status === "pending",
|
|
105
|
+
);
|
|
91
106
|
const state = useMemo<RouterState>(
|
|
92
107
|
() => ({
|
|
93
108
|
location,
|
|
94
|
-
status: "idle",
|
|
95
|
-
isLoading:
|
|
109
|
+
status: pending ? "pending" : "idle",
|
|
110
|
+
isLoading: pending,
|
|
96
111
|
isTransitioning: false,
|
|
97
112
|
matches: [],
|
|
98
113
|
}),
|
|
99
|
-
[location],
|
|
114
|
+
[location, pending],
|
|
100
115
|
);
|
|
101
116
|
return (options?.select ? options.select(state) : state) as T;
|
|
102
117
|
}
|