Skip to content

Commit 7811d4f

Browse files
committed
fix(PrismCode): throw error on non-string code
1 parent 32b4b29 commit 7811d4f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/silly-rocks-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Throw an error if code prop in PrismCode is not a string and not falsy.

src/components/content/PrismCode/PrismCode.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export interface CubePrismCodeProps extends ContainerStyleProps {
8080
function PrismCode(props: CubePrismCodeProps, ref) {
8181
let { code, language = 'javascript', ...otherProps } = props;
8282

83+
if (typeof code !== 'string' && code) {
84+
throw new Error(
85+
'UIKit: code prop should be a string in PrismCode. Found: ' + typeof code,
86+
);
87+
}
88+
8389
const isDiff = isDiffCode(code || '');
8490

8591
useEffect(() => {

0 commit comments

Comments
 (0)