From 33bdfa11d12ae7fb205994c8bcde82fd05a67f2f Mon Sep 17 00:00:00 2001 From: pubuzhixing8 Date: Fri, 19 Apr 2024 17:59:02 +0800 Subject: [PATCH] fix(list-render): fix g hierarchy when add group and element move #WIK-15207 (#841) --- .changeset/slimy-jars-warn.md | 7 +++++++ packages/core/src/core/list-render.ts | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/slimy-jars-warn.md diff --git a/.changeset/slimy-jars-warn.md b/.changeset/slimy-jars-warn.md new file mode 100644 index 000000000..f2a195934 --- /dev/null +++ b/.changeset/slimy-jars-warn.md @@ -0,0 +1,7 @@ +--- +'@plait/core': patch +--- + +fix g hierarchy when add group and element move + +set correctly currentIndexForFirstElement value when move operation and update operation happened on same timing diff --git a/packages/core/src/core/list-render.ts b/packages/core/src/core/list-render.ts index 2f64d148d..0ddd26d6f 100644 --- a/packages/core/src/core/list-render.ts +++ b/packages/core/src/core/list-render.ts @@ -52,7 +52,7 @@ export class ListRender { const newContexts: PlaitPluginElementContext[] = []; const newComponentRefs: ComponentRef[] = []; let currentIndexForFirstElement: number | null = null; - diffResult.forEachItem((record: IterableChangeRecord) => { + diffResult.forEachItem((record: IterableChangeRecord) => { NODE_TO_INDEX.set(record.item, record.currentIndex as number); NODE_TO_PARENT.set(record.item, childrenContext.parent); const previousContext = record.previousIndex === null ? undefined : this.contexts[record.previousIndex]; @@ -68,7 +68,8 @@ export class ListRender { newComponentRefs.push(componentRef); newContexts.push(context); } - if (record.item === this.children[0]) { + // item might has been changed, so need to compare the id + if (record.item === this.children[0] || record.item.id === this.children[0]?.id) { currentIndexForFirstElement = record.currentIndex; } });