diff --git a/package.json b/package.json index 0e29ec85..8c65cd5a 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-is": "^18.2.0", + "rfdc": "^1.3.0", "styled-components": "5.3.3" }, "devDependencies": { @@ -79,4 +80,4 @@ "prettier --write" ] } -} \ No newline at end of file +} diff --git a/src/services/mergeConfigWithCustom/mergeConfigWithCutom.ts b/src/services/mergeConfigWithCustom/mergeConfigWithCutom.ts index ef523647..ff434ee8 100644 --- a/src/services/mergeConfigWithCustom/mergeConfigWithCutom.ts +++ b/src/services/mergeConfigWithCustom/mergeConfigWithCutom.ts @@ -1,4 +1,7 @@ import { memoize, merge } from 'lodash'; +import rfdc from 'rfdc'; + +const clone = rfdc(); type Params = { defaultConfig: T; @@ -10,8 +13,14 @@ const memoizedMerge = memoize( (...args) => JSON.stringify(args[0]) + JSON.stringify(args[1]), ); +const copyMergeMemoize = ({ defaultConfig, custom }: Params): T => { + const defaultConfigClone = clone(defaultConfig); + + return memoizedMerge(defaultConfigClone, custom); +}; + export const mergeConfigWithCustom = ({ defaultConfig, custom, }: Params): T => - custom ? memoizedMerge(defaultConfig, custom) : defaultConfig; + custom ? copyMergeMemoize({ defaultConfig, custom }) : defaultConfig;