From 29e2b22b63d3eb12b209ae56ef6a23dd470c8648 Mon Sep 17 00:00:00 2001 From: "Nolann B." <100787331+nolannbiron@users.noreply.github.com> Date: Fri, 23 Jan 2026 16:01:33 +0100 Subject: [PATCH] Fix ordered list item index calculation (#3935) --- .changeset/public-comics-push.md | 5 +++++ .../gitbook/src/components/DocumentView/ListItem.tsx | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/public-comics-push.md 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: {