-
-
Notifications
You must be signed in to change notification settings - Fork 476
Labels
🐛 bugSomething isn't workingSomething isn't working🚀 enhancementNew feature or requestNew feature or requestconfirmedThis bug was confirmedThis bug was confirmed
Description
- I have searched the Issues to see if this bug has already been reported
- I have tested the latest version
Steps to reproduce
-
Create an empty
flowbite-reactproject -
Add the following code
import * as React from "react"; import { getTheme } from "flowbite-react"; const Child = () => { const theme = getTheme(); return <div>child {theme.accordion.content.base}</div>; }; function App() { const [count, setCount] = React.useState(0); return ( <> <div>count: {count}</div> <button onClick={() => setCount(count + 1)}>inc</button> {Array.from({ length: 1000 }).map((_, i) => { return <Child key={i} />; })} </> ); }
-
Open performance tab of chrome devtool
-
Record the performance
-
Click the inc button 100 times
-
See the result
Current behavior
There are many long tasks. I think the root cause is that we're deep cloning the entire theme object on every render for all components which are using getTheme() API.
// packages/ui/src/helpers/clone-deep.ts
import { isObject } from "./is-object";
export function cloneDeep<T>(source: T): T {
if (!isObject(source)) {
return source;
}
const output: Record<string, unknown> = {};
for (const key in source) {
output[key] = cloneDeep(source[key]);
}
return output as T;
}
// packages/ui/src/theme-store/index.tsx
export function getTheme(): FlowbiteTheme {
return cloneDeep(store.theme);
}Expected behavior
In such a simple project like this, I'm expecting to have no long tasks:
Context
I'm assessing the new UI library for our internal projects.
wtlin1228 and wojciechaniol-identt
Metadata
Metadata
Assignees
Labels
🐛 bugSomething isn't workingSomething isn't working🚀 enhancementNew feature or requestNew feature or requestconfirmedThis bug was confirmedThis bug was confirmed

