seemore 1.12.1 → 1.12.2

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": "seemore",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
4
4
  "description": "Let AI write the Markdown. Let seemore show it better — zero config documentation framework.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import { useSyncExternalStore } from 'react';
2
- import { deserializePageTree } from 'fumadocs-core/source/client';
2
+ import { deserializePageTree, type SerializedPageTree } from 'fumadocs-core/source/client';
3
3
  import type * as PageTree from 'fumadocs-core/page-tree';
4
4
  import { getTree, subscribeTree } from 'virtual:seemore/tree';
5
5
 
@@ -12,7 +12,37 @@ import { getTree, subscribeTree } from 'virtual:seemore/tree';
12
12
  */
13
13
  export function usePageTree(): PageTree.Root {
14
14
  const serialized = useSyncExternalStore(subscribeTree, getTree, getTree);
15
- return deserializePageTree(serialized);
15
+ return resolveTree(serialized);
16
+ }
17
+
18
+ let current: { serialized: SerializedPageTree; content: string; tree: PageTree.Root } | undefined;
19
+ let revision = 0;
20
+
21
+ /**
22
+ * The deserialized tree for a payload, with a root `$id` that moves whenever the tree does.
23
+ *
24
+ * fumadocs' `TreeContextProvider` memoises its tree on `root.$id`, and the loader always calls
25
+ * the root "root" — so without a fresh id a created, renamed or retitled page reaches the
26
+ * store and never the sidebar. The id only moves when the content differs: the store is
27
+ * replaced on body edits too, and the sidebar list is keyed on that id, so bumping it for
28
+ * nothing would remount the list and close every folder the reader opened, on every save.
29
+ * The first tree keeps its id, so prerendered HTML and hydration agree. Exported for the
30
+ * tree store test.
31
+ */
32
+ export function resolveTree(serialized: SerializedPageTree): PageTree.Root {
33
+ if (current?.serialized === serialized) return current.tree;
34
+
35
+ // Measured before deserialising: fumadocs rewrites names and icons into elements in place.
36
+ const content = JSON.stringify(serialized);
37
+ if (current?.content === content) {
38
+ current = { ...current, serialized };
39
+ return current.tree;
40
+ }
41
+
42
+ const tree = deserializePageTree(serialized);
43
+ if (current !== undefined) tree.$id = `${tree.$id ?? 'root'}:${++revision}`;
44
+ current = { serialized, content, tree };
45
+ return tree;
16
46
  }
17
47
 
18
48
  /**