Skip to content

Commit 40b27b7

Browse files
committed
create issue component with unique key based issue id and counter.
1 parent 08ec6e7 commit 40b27b7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/components/MarkdownRenderer.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ export default defineComponent({
5151
},
5252

5353
setup(props) {
54+
const componentCount: {[key: string]: Record<string, number>} = {};
55+
56+
const resetCounter = () => {
57+
Object.keys(componentCount).forEach((key) => {
58+
componentCount[key] = {};
59+
})
60+
}
61+
62+
const getNextKey = (type: string, id: string) => {
63+
const counter = componentCount[type] ||= {};
64+
const count = counter[id] || 0;
65+
counter[id] = count + 1;
66+
const key = `${type}-${id}-${count}`;
67+
return key;
68+
}
69+
5470
const walkNodes = (node: HTMLElement): any => {
5571
// h()でvNodeを作る時点で子ノードの一覧が必要になるため、以下の順で処理します。
5672
// 1. visit: vNode作成の基本情報
@@ -152,10 +168,14 @@ export default defineComponent({
152168
return newVNode;
153169
},
154170
departIssue(node: HTMLElement, vNode: VNode): VNode {
171+
const id = node.dataset["issue"] as string;
172+
const key = getNextKey("issue", id);
173+
155174
const newVNode: VNode = {
156175
type: MarkdownRendererIssue,
157176
props: {
158-
id: node.dataset["issue"],
177+
key,
178+
id,
159179
},
160180
children: null,
161181
};
@@ -172,6 +192,7 @@ export default defineComponent({
172192
const outer = document.createElement("div");
173193
outer.innerHTML = props.content;
174194

195+
resetCounter()
175196
return walkNodes(outer);
176197
};
177198
},

0 commit comments

Comments
 (0)