Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 73cf9cd57f fix: guard MobileBreadcrumb against single-element links array
https://sonarly.com/issue/28983?type=bug

MobileBreadcrumb crashes with TypeError when accessing `.children` on `undefined` because it assumes the `links` array always has at least 2 elements, but FormAdvancedTextFieldInput provides a default breadcrumb array with only 1 element when fullscreen text editing is triggered on mobile.

Fix: Changed the guard condition in Breadcrumb.tsx from `links.length > 0` to `links.length >= 2` before delegating to MobileBreadcrumb. MobileBreadcrumb assumes the links array always has at least 2 elements (it accesses `links[links.length - 2]`), but the guard only checked for > 0, allowing 1-element arrays through. When FormAdvancedTextFieldInput's default single-element breadcrumb array reached MobileBreadcrumb on mobile, `links[-1]` evaluated to `undefined` and accessing `.children` threw the TypeError. With this fix, 1-element arrays on mobile fall through to the desktop breadcrumb rendering, which safely handles any array length via `.map()`. All existing callers that pass 2+ element arrays are completely unaffected — they still route to MobileBreadcrumb as before.
2026-04-20 14:28:55 +00:00
@@ -46,7 +46,7 @@ const StyledDivider = styled.span`
export const Breadcrumb = ({ className, links }: BreadcrumbProps) => {
const isMobile = useIsMobile();
if (isMobile && links.length > 0) {
if (isMobile && links.length >= 2) {
return <MobileBreadcrumb className={className} links={links} />;
}