Skip to content

Commit 822c1d4

Browse files
authored
[WC-3183] Fix key prop violation warning for HTMLElement. (#1988)
2 parents 0c2933c + 3c8c600 commit 822c1d4

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
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. Thanks @Andries-Smit and @DiljohnSingh for your contributions!
12+
913
## [1.2.2] - 2025-03-14
1014

1115
### Security

packages/pluggableWidgets/html-element-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"dependencies": {
4444
"@mendix/widget-plugin-component-kit": "workspace:*",
45-
"dompurify": "^3.2.6"
45+
"dompurify": "^3.3.0"
4646
},
4747
"devDependencies": {
4848
"@mendix/automation-utils": "workspace:*",

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 () => {

packages/pluggableWidgets/rich-text-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@uiw/codemirror-theme-github": "^4.23.13",
5151
"@uiw/react-codemirror": "^4.23.13",
5252
"classnames": "^2.5.1",
53-
"dompurify": "^3.2.6",
53+
"dompurify": "^3.3.0",
5454
"js-beautify": "^1.15.4",
5555
"katex": "^0.16.22",
5656
"linkifyjs": "^4.3.2",

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)