@octanejs/tanstack-router 0.1.52 → 0.1.54

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/tanstack-router",
3
- "version": "0.1.52",
3
+ "version": "0.1.54",
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.63",
65
+ "@tsrx/react": "^0.3.0",
66
66
  "esbuild": "^0.28.1",
67
- "react": "^19.2.7",
68
- "react-dom": "^19.2.7",
67
+ "react": "19.2.7",
68
+ "react-dom": "19.2.7",
69
69
  "vitest": "^4.1.10",
70
- "octane": "0.2.3"
70
+ "octane": "0.2.14"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run"
@@ -3,7 +3,6 @@ import {
3
3
  deepEqual,
4
4
  escapeHtml,
5
5
  getAssetCrossOrigin,
6
- getScriptPreloadAttrs,
7
6
  resolveManifestCssLink,
8
7
  } from '@tanstack/router-core';
9
8
  import { isServer } from '@tanstack/router-core/isServer';
@@ -80,7 +79,6 @@ function buildTagsFromMatches(
80
79
  .map((link) => ({ tag: 'link', attrs: { ...link, nonce } }) satisfies RouterManagedTag);
81
80
 
82
81
  const manifestTags: Array<RouterManagedTag> = [];
83
- const preloadTags: Array<RouterManagedTag> = [];
84
82
  const manifest = router.ssr?.manifest;
85
83
  if (manifest) {
86
84
  for (const match of matches) {
@@ -97,15 +95,6 @@ function buildTagsFromMatches(
97
95
  },
98
96
  });
99
97
  }
100
- for (const preload of manifest.routes[match.routeId]?.preloads ?? []) {
101
- preloadTags.push({
102
- tag: 'link',
103
- attrs: {
104
- ...getScriptPreloadAttrs(manifest, preload, assetCrossOrigin),
105
- nonce,
106
- },
107
- });
108
- }
109
98
  }
110
99
 
111
100
  if (manifest.inlineStyle) {
@@ -144,7 +133,6 @@ function buildTagsFromMatches(
144
133
 
145
134
  const tags: Array<RouterManagedTag> = [];
146
135
  appendUniqueUserTags(tags, resultMeta);
147
- tags.push(...preloadTags);
148
136
  appendUniqueUserTags(tags, links);
149
137
  tags.push(...manifestTags);
150
138
  appendUniqueUserTags(tags, styles);
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
- // Memoize selector output: same store input → same output; structurally-equal
49
- // output keeps its previous reference (so useSyncExternalStore doesn't loop).
50
- const cache = useRef<{ in: unknown; out: unknown } | null>(null, subSlot(slot, 'us:cache'));
51
- const getSnapshot = (): unknown => {
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 (prev && Object.is(prev.in, input)) return prev.out;
55
- const next = selector(input);
56
- if (prev && compare(prev.out, next)) {
57
- cache.current = { in: input, out: prev.out };
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
- cache.current = { in: input, out: next };
61
- return next;
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
  }