Skip to content

Commit 4822f58

Browse files
Fix JavaScript null handling for sidebar on Identity pages
Co-authored-by: BenjaminMichaelis <[email protected]>
1 parent a68ec41 commit 4822f58

File tree

1 file changed

+13
-8
lines changed
  • EssentialCSharp.Web/wwwroot/js

1 file changed

+13
-8
lines changed

EssentialCSharp.Web/wwwroot/js/site.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useChatWidget } from "./chat-module.js";
2020
* @prop {TocItem[]} [items]
2121
*/
2222
/** @type {TocItem} */
23-
const tocData = markRaw(TOC_DATA);
23+
const tocData = markRaw(TOC_DATA || []);
2424

2525
//Add new content or features here:
2626

@@ -80,6 +80,9 @@ const completedFeaturesList = [
8080
* @returns {TocItem[] | undefined} path of items to the current page
8181
* */
8282
function findCurrentPage(path, items) {
83+
if (!items || !Array.isArray(items)) {
84+
return null;
85+
}
8386
for (const item of items) {
8487
const itemPath = [item, ...path];
8588
if (
@@ -286,8 +289,8 @@ const app = createApp({
286289
const searchQuery = ref('');
287290

288291
const filteredTocData = computed(() => {
289-
if (!searchQuery.value) {
290-
return tocData;
292+
if (!searchQuery.value || !tocData) {
293+
return tocData || [];
291294
}
292295
const query = normalizeString(searchQuery.value);
293296
return tocData.filter(item => filterItem(item, query));
@@ -318,11 +321,13 @@ const app = createApp({
318321
else {
319322
expandedTocs.clear();
320323
const query = normalizeString(newQuery);
321-
tocData.forEach(item => {
322-
if (filterItem(item, query)) {
323-
expandedTocs.add(item.key);
324-
}
325-
});
324+
if (tocData) {
325+
tocData.forEach(item => {
326+
if (filterItem(item, query)) {
327+
expandedTocs.add(item.key);
328+
}
329+
});
330+
}
326331
}
327332
});
328333

0 commit comments

Comments
 (0)