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:
1 parent
ebcea5d0cb
commit
b572112ae7
5 files changed
+118
-4
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user