@clidey/dory 0.43.0 → 0.44.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.44.0",
5
5
  "type": "module",
6
6
  "description": "A CLI tool for building and previewing documentation sites",
7
7
  "keywords": [
@@ -83,21 +83,24 @@ 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 — don't block page rendering.
100
+ // Each page's raw MDX is fetched individually, so for large sites this
101
+ // can be hundreds of requests. We batch them to avoid overwhelming the
102
+ // browser's connection pool.
103
+ addPreloadedContentToSearch();
101
104
  }
102
105
  }
103
106
  } catch (error) {
@@ -105,29 +108,34 @@ export async function preloadFrontmatter() {
105
108
  }
106
109
  }
107
110
 
108
- // Add preloaded content to search index
111
+ // Add preloaded content to search index (runs in background, never blocks rendering)
109
112
  async function addPreloadedContentToSearch() {
110
113
  if (!preloadedFrontMatter) return;
111
-
114
+
112
115
  const mdxFiles = import.meta.glob<{ default: string }>('../../docs/**/*.mdx', { query: '?raw' });
113
116
  const fileEntries = Object.entries(mdxFiles);
114
117
 
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);
118
+ // Index in batches to avoid firing hundreds of requests at once
119
+ const BATCH_SIZE = 10;
120
+ for (let i = 0; i < preloadedFrontMatter.length; i += BATCH_SIZE) {
121
+ const batch = preloadedFrontMatter.slice(i, i + BATCH_SIZE);
122
+ await Promise.all(
123
+ batch.map(async (fm) => {
124
+ const fileEntry = fileEntries.find(([filePath]) => pathFromFilename(filePath) === fm.path);
125
+ if (fileEntry) {
126
+ try {
127
+ const [, loader] = fileEntry;
128
+ const rawContent = (await loader()).default;
129
+ const { content } = parseFrontMatter(rawContent);
130
+
131
+ await addToSearchIndex(fm.path, { title: fm.title }, content);
132
+ } catch (error) {
133
+ console.warn(`Failed to index ${fm.path}:`, error);
134
+ }
127
135
  }
128
- }
129
- })
130
- );
136
+ })
137
+ );
138
+ }
131
139
  }
132
140
 
133
141
  // Load frontmatter for a specific pathname (optimized with fallback)