From dcdc06e7ce710a03da3c7a21479d0c7a9add6b02 Mon Sep 17 00:00:00 2001 From: Youssef Henna Date: Wed, 20 Nov 2024 15:02:41 +0100 Subject: [PATCH] Handle value not an object in `isTextStyleObject` --- packages/theme/src/utils.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/theme/src/utils.ts b/packages/theme/src/utils.ts index ef8b24fd1..a9e51ebee 100644 --- a/packages/theme/src/utils.ts +++ b/packages/theme/src/utils.ts @@ -2,16 +2,22 @@ import { isObject } from "lodash"; import type { ThemeValues } from "./types"; export function isTextStyleObject(value: any): boolean { - return Object.keys(value).some((key) => - [ - "fontFamily", - "fontWeight", - "fontSize", - "fontStyle", - "lineHeight", - "letterSpacing", - ].includes(key) - ); + try { + return Object.keys(value).some((key) => + [ + "fontFamily", + "fontWeight", + "fontSize", + "fontStyle", + "lineHeight", + "letterSpacing", + ].includes(key) + ); + } catch (e) { + // If `value` is not an object, the above code will throw an error + // Catch error and return false is more efficient than a call to `isObject` + return false; + } } export function asThemeValuesObject(value: any): ThemeValues | null {