diff --git a/.changeset/public-comics-push.md b/.changeset/public-comics-push.md new file mode 100644 index 000000000..1f1687962 --- /dev/null +++ b/.changeset/public-comics-push.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix ordered list item index calculation diff --git a/packages/gitbook/src/components/DocumentView/ListItem.tsx b/packages/gitbook/src/components/DocumentView/ListItem.tsx index fd24ab2f9..9c6a734d0 100644 --- a/packages/gitbook/src/components/DocumentView/ListItem.tsx +++ b/packages/gitbook/src/components/DocumentView/ListItem.tsx @@ -182,8 +182,16 @@ function getOrderedListItemPrefixContent(input: { }): string { const { parent, block } = input; const start = parent.data.start ?? 1; - const index = parent.nodes.findIndex((node) => node.key === block.key) ?? 0; - const value = index + start; + + let index: number; + // If the block has a key, use it to find the index. Otherwise, use the object reference. + if (block.key) { + index = parent.nodes.findIndex((node) => node.key === block.key); + } else { + index = parent.nodes.findIndex((node) => node === block); + } + + const value = index >= 0 ? index + start : Math.max(start, 1); switch (input.depth % 3) { // Use numbers case 0: {