Skip to content

Commit

Permalink
fix unwanted widget rerenders in HomeLayout when resizing (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauldom102 authored Mar 4, 2025
1 parent b33038d commit 5b29a20
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions lib/experimental/PageLayouts/HomeLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Carousel } from "@/experimental/Navigation/Carousel"
import { cn } from "@/lib/utils"
import {
Children,
forwardRef,
Expand All @@ -25,23 +26,32 @@ export const HomeLayout = forwardRef<HTMLDivElement, Props>(function HomeLayout(

const canShowContent = !!width

const isSmallerScreen = canShowContent && width < 992
const isSmallerScreen = canShowContent && width < 1024

let arrayWidgets = Children.toArray(widgets).filter((widget) => !!widget)

if (isSmallerScreen) {
arrayWidgets = arrayWidgets.map((widget, i) => (
<div key={i} className="h-full [&>div]:h-full [&>div]:shadow-none">
const arrayWidgets = Children.toArray(widgets)
.filter((widget) => !!widget)
.map((widget, i) => (
<div
key={i}
className={cn(
isSmallerScreen && "h-full [&>div]:h-full [&>div]:shadow-none"
)}
>
{widget}
</div>
))
return (
<div
ref={ref}
className="flex flex-col gap-6 px-5 pb-5 pt-4 md:px-3 md:pb-3 md:pt-2"
>
{canShowContent && (
<>

return (
<div ref={ref}>
{canShowContent && (
<>
{/* Smaller screen content */}
<div
className={cn(
"flex flex-col gap-6 px-5 pb-5 pt-4 md:px-3 md:pb-3 md:pt-2",
!isSmallerScreen && "hidden"
)}
>
<Carousel
columns={{
xs: 1,
Expand All @@ -54,24 +64,24 @@ export const HomeLayout = forwardRef<HTMLDivElement, Props>(function HomeLayout(
{arrayWidgets}
</Carousel>
<main>{children}</main>
</>
)}
</div>
)
}

return (
<div ref={ref} className="grid grid-cols-3 gap-6 px-6 pb-6 pt-2">
{canShowContent && (
<>
<div className="col-span-3 flex flex-row gap-6 *:flex-1">
{arrayWidgets.slice(0, 3)}
</div>

<main className="col-span-2">{children}</main>
{/* Larger screen content */}
<div
className={cn(
"grid grid-cols-3 gap-6 px-6 pb-6 pt-2",
isSmallerScreen && "hidden"
)}
>
<div className="col-span-3 flex flex-row gap-6 *:flex-1">
{arrayWidgets.slice(0, 3)}
</div>

<main className="col-span-2">{children}</main>

<div className="flex flex-1 flex-col gap-6">
{arrayWidgets.slice(3)}
<div className="flex flex-1 flex-col gap-6">
{arrayWidgets.slice(3)}
</div>
</div>
</>
)}
Expand Down

0 comments on commit 5b29a20

Please sign in to comment.