Allow merged indexes to be marked optional

A merged index that failed to load made mergeIndex throw, and the
failed instance stayed in the list, so search stopped working for
every index. Indexes passed with `optional: true` are now dropped
with a warning when they fail to load, and search runs over the
indexes that did load.

Fixes #887
This commit is contained in:
dualfroz committed 2026-10-03 01:37:54 +02:00
1 parent ebcea5d0cb
commit b572112ae7
5 files changed
+118 -4

No files matched your search

+13 -4
View File
@@ -909,11 +909,20 @@ export class Pagefind {
await asyncSleep(50);
}
await newInstance.init(options.language || this.primaryLanguage, {
load_wasm: false,
});
try {
await newInstance.init(options.language || this.primaryLanguage, {
load_wasm: false,
});
} catch (e) {
if (!options.optional) throw e;
this.instances = this.instances.filter((i) => i !== newInstance);
console.warn(
`Skipping optional mergeIndex ${indexPath} that failed to load`,
);
return;
}
const { language, ...remainingOptions } = options;
const { language, optional, ...remainingOptions } = options;
await newInstance.options(remainingOptions);
}
+6
View File
@@ -28,6 +28,12 @@ declare global {
*/
highlightParam?: string;
language?: string;
/**
* If set, a merged index that fails to load is skipped instead of failing the whole search.
*
* Only applies in multisite setups, to indexes passed to mergeIndex.
*/
optional?: boolean;
/**
* Whether an instance of Pagefind is the primary index or not (for multisite).
*