Skip to content

Commit 70ca789

Browse files
r0b1nDiljohnSinghAndries-Smit
committed
fix: an issue with key prop warning
Co-authored-by: Diljohn Singh <[email protected]> Co-authored-by: Andries Smit <[email protected]>
1 parent f67d586 commit 70ca789

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

packages/pluggableWidgets/html-element-web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We fixed a warning related to non-unique "key" props that appeared in certain scenarios.
12+
913
## [1.2.2] - 2025-03-14
1014

1115
### Security

packages/pluggableWidgets/html-element-web/src/HTMLElement.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, JSX, ReactElement } from "react";
1+
import { Fragment, JSX, ReactElement, useId } from "react";
22

33
import { HTMLElementContainerProps } from "../typings/HTMLElementProps";
44
import {
@@ -16,15 +16,17 @@ export function HTMLElement(props: HTMLElementContainerProps): ReactElement | nu
1616
const tag = prepareTag(props.tagName, props.tagNameCustom);
1717
const items = props.tagUseRepeat ? props.tagContentRepeatDataSource?.items : [undefined];
1818

19+
const id = useId();
20+
1921
if (!items?.length) {
2022
return null;
2123
}
2224

2325
return (
2426
<Fragment>
25-
{items.map(item => (
27+
{items.map((item, index) => (
2628
<HTMLTag
27-
key={item?.id}
29+
key={`${id}_${item?.id || index}`}
2830
tagName={tag as keyof JSX.IntrinsicElements}
2931
attributes={{
3032
...prepareAttributes(createAttributeResolver(item), props.attributes, props.class, props.style),

packages/pluggableWidgets/html-element-web/src/components/__tests__/HTMLTag.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("HTMLTag", () => {
3737
});
3838

3939
it("with innerHTML apply html sanitizing", () => {
40-
const checkSapshot = (html: string): void => {
40+
const checkSnapshot = (html: string): void => {
4141
expect(
4242
render(
4343
<HTMLTag
@@ -53,10 +53,10 @@ describe("HTMLTag", () => {
5353
).toMatchSnapshot();
5454
};
5555

56-
checkSapshot("<p>Lorem ipsum <script>alert(1)</script></p>");
57-
checkSapshot("<img src=x onerror=alert(1)>");
58-
checkSapshot(`<b onmouseover=alert(‘XSS testing!‘)>ok</b>`);
59-
checkSapshot("<a>123</a><option><style><img src=x onerror=alert(1)></style>");
56+
checkSnapshot("<p>Lorem ipsum <script>alert(1)</script></p>");
57+
checkSnapshot("<img src=x onerror=alert(1)>");
58+
checkSnapshot(`<b onmouseover=alert(‘XSS testing!‘)>ok</b>`);
59+
checkSnapshot("<a>123</a><option><style><img src=x onerror=alert(1)></style>");
6060
});
6161

6262
it("fires events", async () => {

0 commit comments

Comments
 (0)