@clidey/dory 0.43.0 → 0.45.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clidey/dory",
3
3
  "private": false,
4
- "version": "0.43.0",
4
+ "version": "0.45.0",
5
5
  "type": "module",
6
6
  "description": "A CLI tool for building and previewing documentation sites",
7
7
  "keywords": [
@@ -83,21 +83,22 @@ let preloadedFrontMatter: Record<string, any>[] | null = null;
83
83
  // Preload frontmatter from JSON file (optimized approach)
84
84
  export async function preloadFrontmatter() {
85
85
  if (preloadedFrontMatter) return; // Already loaded
86
-
86
+
87
87
  try {
88
88
  const response = await fetch('/frontmatter.json');
89
89
  if (response.ok) {
90
90
  preloadedFrontMatter = await response.json();
91
91
  if (preloadedFrontMatter) {
92
92
  completeFrontMatter = [...preloadedFrontMatter];
93
-
93
+
94
94
  // Update navigation titles from preloaded data
95
95
  for (const fm of preloadedFrontMatter) {
96
96
  updateNavigationTitle(fm.path, fm.title);
97
97
  }
98
-
99
- // Add to search index
100
- await addPreloadedContentToSearch();
98
+
99
+ // Build search index in the background after the page has fully rendered.
100
+ // Delay avoids competing with the route chunk for network connections.
101
+ setTimeout(() => addPreloadedContentToSearch(), 2000);
101
102
  }
102
103
  }
103
104
  } catch (error) {
@@ -105,29 +106,34 @@ export async function preloadFrontmatter() {
105
106
  }
106
107
  }
107
108
 
108
- // Add preloaded content to search index
109
+ // Add preloaded content to search index (runs in background, never blocks rendering)
109
110
  async function addPreloadedContentToSearch() {
110
111
  if (!preloadedFrontMatter) return;
111
-
112
+
112
113
  const mdxFiles = import.meta.glob<{ default: string }>('../../docs/**/*.mdx', { query: '?raw' });
113
114
  const fileEntries = Object.entries(mdxFiles);
114
115
 
115
- await Promise.all(
116
- preloadedFrontMatter.map(async (fm) => {
117
- const fileEntry = fileEntries.find(([filePath]) => pathFromFilename(filePath) === fm.path);
118
- if (fileEntry) {
119
- try {
120
- const [, loader] = fileEntry;
121
- const rawContent = (await loader()).default;
122
- const { content } = parseFrontMatter(rawContent);
123
-
124
- await addToSearchIndex(fm.path, { title: fm.title }, content);
125
- } catch (error) {
126
- console.warn(`Failed to index ${fm.path}:`, error);
116
+ // Index in batches to avoid firing hundreds of requests at once
117
+ const BATCH_SIZE = 10;
118
+ for (let i = 0; i < preloadedFrontMatter.length; i += BATCH_SIZE) {
119
+ const batch = preloadedFrontMatter.slice(i, i + BATCH_SIZE);
120
+ await Promise.all(
121
+ batch.map(async (fm) => {
122
+ const fileEntry = fileEntries.find(([filePath]) => pathFromFilename(filePath) === fm.path);
123
+ if (fileEntry) {
124
+ try {
125
+ const [, loader] = fileEntry;
126
+ const rawContent = (await loader()).default;
127
+ const { content } = parseFrontMatter(rawContent);
128
+
129
+ await addToSearchIndex(fm.path, { title: fm.title }, content);
130
+ } catch (error) {
131
+ console.warn(`Failed to index ${fm.path}:`, error);
132
+ }
127
133
  }
128
- }
129
- })
130
- );
134
+ })
135
+ );
136
+ }
131
137
  }
132
138
 
133
139
  // Load frontmatter for a specific pathname (optimized with fallback)