Skip to content

Commit 18f7895

Browse files
Fix algolia returing a null value on lvl1 on certain pages (#1175)
1 parent 23f5b5a commit 18f7895

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/bindings/DocSearch.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type contentType =
1010
| @as("lvl6") Lvl6
1111

1212
type hierarchy = {
13-
lvl0: string,
14-
lvl1: string,
13+
lvl0: Nullable.t<string>,
14+
lvl1: Nullable.t<string>,
1515
lvl2: Nullable.t<string>,
1616
lvl3: Nullable.t<string>,
1717
lvl4: Nullable.t<string>,

src/components/Search.res

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,25 @@ let transformItems = (items: DocSearch.transformItems) => {
5959
| Some({pathname, hash}) =>
6060
RegExp.test(/v(8|9|10|11)\./, pathname)
6161
? None
62-
: Some({
63-
...item,
64-
deprecated: pathname->String.includes("api/js") || pathname->String.includes("api/core")
65-
? Some("Deprecated")
66-
: None,
67-
url: pathname->String.replace("/v12.0.0/", "/") ++ hash,
68-
})
62+
: {
63+
// DocSearch internally calls .replace() on hierarchy.lvl1, so we must
64+
// provide a fallback for items where lvl1 is null to prevent crashes
65+
let hierarchy = item.hierarchy
66+
let lvl0 = hierarchy.lvl0->Nullable.toOption->Option.getOr("")
67+
let lvl1 = hierarchy.lvl1->Nullable.toOption->Option.getOr(lvl0)
68+
Some({
69+
...item,
70+
deprecated: pathname->String.includes("api/js") || pathname->String.includes("api/core")
71+
? Some("Deprecated")
72+
: None,
73+
url: pathname->String.replace("/v12.0.0/", "/") ++ hash,
74+
hierarchy: {
75+
...hierarchy,
76+
lvl0: Nullable.make(lvl0),
77+
lvl1: Nullable.make(lvl1),
78+
},
79+
})
80+
}
6981
| None => None
7082
}
7183
})

0 commit comments

Comments
 (0)