Update JSONNestedNode.tsx to better handle sparse array inputs

This commit is contained in:
Roger Tuan 2025-02-07 12:38:45 -08:00 committed by GitHub
parent 750046c4d9
commit 2160aaa534
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,7 @@ interface Entry {
} }
function isRange(rangeOrEntry: Range | Entry): rangeOrEntry is Range { function isRange(rangeOrEntry: Range | Entry): rangeOrEntry is Range {
return (rangeOrEntry as Range).to !== undefined; return (rangeOrEntry as Range)?.to !== undefined;
} }
function renderChildNodes( function renderChildNodes(
@ -54,6 +54,10 @@ function renderChildNodes(
from, from,
to, to,
).forEach((entry) => { ).forEach((entry) => {
// Don't process null/undefined entries, which can come from sparse arrays
if(!entry) {
return
}
if (isRange(entry)) { if (isRange(entry)) {
childNodes.push( childNodes.push(
<ItemRange <ItemRange