diff --git a/.changeset/tender-wasps-change.md b/.changeset/tender-wasps-change.md new file mode 100644 index 000000000..04938b598 --- /dev/null +++ b/.changeset/tender-wasps-change.md @@ -0,0 +1,5 @@ +--- +"@suid/material": patch +--- + +Improves performance by avoiding double renderings (`Avatar`, `Alert`, `Button`, `Divider`, `ListItem`, `SvgIcon`) diff --git a/packages/material/src/Alert/Alert.tsx b/packages/material/src/Alert/Alert.tsx index d6407aa23..340708b07 100644 --- a/packages/material/src/Alert/Alert.tsx +++ b/packages/material/src/Alert/Alert.tsx @@ -12,7 +12,7 @@ import alertClasses, { getAlertUtilityClass } from "./alertClasses"; import createComponentFactory from "@suid/base/createComponentFactory"; import { darken, lighten } from "@suid/system"; import clsx from "clsx"; -import { Show } from "solid-js"; +import { Show, createMemo } from "solid-js"; const $ = createComponentFactory()({ name: "MuiAlert", @@ -168,6 +168,8 @@ const Alert = $.component(function Alert({ otherProps, props, }) { + const icon = createMemo(() => props.icon); + const action = createMemo(() => props.action); return ( - + - {props.icon || + {icon() || props.iconMapping?.[props.severity]?.() || defaultIconMapping[props.severity]?.()} @@ -186,10 +188,10 @@ const Alert = $.component(function Alert({ {otherProps.children} - - {props.action} + + {action()} - + - - - {props.startIcon} - + + {(startIcon) => ( + + {startIcon()} + + )} {props.children} - - - {props.endIcon} - + + {(endIcon) => ( + + {endIcon()} + + )} ); diff --git a/packages/material/src/Divider/Divider.tsx b/packages/material/src/Divider/Divider.tsx index 7839ff1a5..6b46c264b 100644 --- a/packages/material/src/Divider/Divider.tsx +++ b/packages/material/src/Divider/Divider.tsx @@ -219,9 +219,11 @@ const Divider = $.component(function Divider({ class={clsx(classes.root, allProps.class)} > - - {allProps.children} - + {(children) => ( + + {children()} + + )} ); diff --git a/packages/material/src/ListItem/ListItem.tsx b/packages/material/src/ListItem/ListItem.tsx index 1dee35273..bf9b321bf 100644 --- a/packages/material/src/ListItem/ListItem.tsx +++ b/packages/material/src/ListItem/ListItem.tsx @@ -208,10 +208,12 @@ const ListItem = $.component(function ListItem({ {...componentProps} > {props.children} - - - {props.secondaryAction} - + + {(secondaryAction) => ( + + {secondaryAction()} + + )} diff --git a/packages/material/src/SvgIcon/SvgIcon.tsx b/packages/material/src/SvgIcon/SvgIcon.tsx index c6a81ca38..0d670b368 100644 --- a/packages/material/src/SvgIcon/SvgIcon.tsx +++ b/packages/material/src/SvgIcon/SvgIcon.tsx @@ -113,8 +113,8 @@ const SvgIcon = $.component(function SvgIcon({ ownerState={allProps} > {props.children} - - {props.titleAccess} + + {(titleAccess) => {titleAccess()}} );