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

+24
View File
@@ -155,6 +155,30 @@ await pagefind.mergeIndex("https://docs.example.com/pagefind", {
```
{{< /diffcode >}}
## Skipping indexes that fail to load
By default, a merged index that can't be loaded stops search from working. If some of your indexes might be missing, for example while one of the sites hasn't been built yet, pass an `optional` option for those indexes. Pagefind will log a warning and search across the indexes that did load:
{{< diffcode >}}
```js
// Component UI:
const { configureInstance } = window.PagefindComponents;
configureInstance("default", {
mergeIndex: [{
bundlePath: "https://docs.example.com/pagefind",
+ optional: true
}]
});
// JS API:
const pagefind = await import("/pagefind/pagefind.js");
await pagefind.mergeIndex("https://docs.example.com/pagefind", {
+ optional: true
});
```
{{< /diffcode >}}
## Notes
### Cross origin indexes