@octanejs/tanstack-router 0.1.51 → 0.1.53
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 -0
- package/package.json +3 -3
- package/src/router.ts +5 -21
- package/src/useStore.ts +25 -11
package/README.md
CHANGED
|
@@ -62,6 +62,15 @@ tree renders **pull-based**: `RouterProvider` renders the first match, and each
|
|
|
62
62
|
component's `<Outlet/>` looks up the next match via `matchContext` — so navigation
|
|
63
63
|
re-renders only the matches that changed.
|
|
64
64
|
|
|
65
|
+
## Same-route search navigation
|
|
66
|
+
|
|
67
|
+
Same-route search navigations now render store updates urgently. If the route
|
|
68
|
+
component suspends on the new search input, its pending fallback can replace the
|
|
69
|
+
current content; the previous automatic same-route hold no longer applies. To
|
|
70
|
+
retain stale content while the new data loads, use `useDeferredValue` from `octane`
|
|
71
|
+
on the search input (for example, `page`) and render the suspending content from
|
|
72
|
+
that deferred value. The router location still advances when navigation commits.
|
|
73
|
+
|
|
65
74
|
## Scope
|
|
66
75
|
|
|
67
76
|
Included: `createRouter`, `createRootRoute`, `createRoute`, `RouterProvider`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/tanstack-router",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@tanstack/react-router": "1.170.18",
|
|
65
|
-
"@tsrx/react": "^0.2.
|
|
65
|
+
"@tsrx/react": "^0.2.67",
|
|
66
66
|
"esbuild": "^0.28.1",
|
|
67
67
|
"react": "^19.2.7",
|
|
68
68
|
"react-dom": "^19.2.7",
|
|
69
69
|
"vitest": "^4.1.10",
|
|
70
|
-
"octane": "0.2.
|
|
70
|
+
"octane": "0.2.4"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "vitest run"
|
package/src/router.ts
CHANGED
|
@@ -23,27 +23,11 @@ import type {
|
|
|
23
23
|
|
|
24
24
|
const isServerEnv = typeof document === 'undefined';
|
|
25
25
|
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// Why this is needed: router-core already wraps navigation in
|
|
33
|
-
// `router.startTransition` (Transitioner.tsrx), but the RESOLVED commit is run
|
|
34
|
-
// inside `startViewTransition(fn)`, and a real browser defers `fn` to a later
|
|
35
|
-
// task. By then octane's transition window (TRANSITION_DEPTH / the async
|
|
36
|
-
// `startTransition` window) has closed, so the commit would schedule an URGENT
|
|
37
|
-
// re-render. For a same-route `?page` change that urgent re-render lands on a
|
|
38
|
-
// suspending descendant (the route component reading `useSearch`), and an urgent
|
|
39
|
-
// suspend does NOT hold — the route's pending fallback flashes. Re-asserting the
|
|
40
|
-
// transition AT COMMIT TIME makes that re-render ride the concurrent-navigation
|
|
41
|
-
// transition, so octane keeps the current page on screen until the new one is
|
|
42
|
-
// ready (matching cross-route navigation). `startTransition` is re-entrant, so
|
|
43
|
-
// nesting (router-core's own startTransition → this batch) is a no-op extra
|
|
44
|
-
// level; non-navigation router commits ride a transition too, which is harmless
|
|
45
|
-
// (router stores are only ever mutated by router internals, never by urgent user
|
|
46
|
-
// state). SSR uses the non-reactive factory below and is unaffected.
|
|
26
|
+
// Batch router mutations atomically, including resolved commits delivered by a
|
|
27
|
+
// later View Transition callback. The transition scope preserves navigation
|
|
28
|
+
// bookkeeping; useSyncExternalStore notifications still render urgently. Routes
|
|
29
|
+
// that keep stale content while new data loads should defer their render input
|
|
30
|
+
// with useDeferredValue. Server snapshots use the non-reactive factory below.
|
|
47
31
|
const octaneStoreFactory = (opts: { isServer?: boolean }) => {
|
|
48
32
|
if (opts?.isServer ?? isServerEnv) {
|
|
49
33
|
return {
|
package/src/useStore.ts
CHANGED
|
@@ -45,21 +45,35 @@ export function useStore(...args: any[]): any {
|
|
|
45
45
|
subSlot(slot, 'us:cb'),
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
// A cached snapshot belongs to its atom, selector, and comparator as well as
|
|
49
|
+
// its input. Route parameters captured by a new selector must be re-evaluated
|
|
50
|
+
// even when the atom has already published the current match-id list.
|
|
51
|
+
// Structurally-equal output keeps its previous reference so
|
|
52
|
+
// useSyncExternalStore does not loop on allocating selectors.
|
|
53
|
+
const cache = useRef<{
|
|
54
|
+
atom: Atom<unknown>;
|
|
55
|
+
in: unknown;
|
|
56
|
+
selector: typeof selector;
|
|
57
|
+
compare: typeof compare;
|
|
58
|
+
out: unknown;
|
|
59
|
+
} | null>(null, subSlot(slot, 'us:cache'));
|
|
60
|
+
function getSnapshot(): unknown {
|
|
52
61
|
const input = atom.get();
|
|
53
62
|
const prev = cache.current;
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
if (
|
|
64
|
+
prev &&
|
|
65
|
+
prev.atom === atom &&
|
|
66
|
+
prev.selector === selector &&
|
|
67
|
+
prev.compare === compare &&
|
|
68
|
+
Object.is(prev.in, input)
|
|
69
|
+
) {
|
|
58
70
|
return prev.out;
|
|
59
71
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
const next = selector(input);
|
|
73
|
+
const out = prev && compare(prev.out, next) ? prev.out : next;
|
|
74
|
+
cache.current = { atom, in: input, selector, compare, out };
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
63
77
|
|
|
64
78
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot, subSlot(slot, 'us:uses'));
|
|
65
79
|
}
|