From dc5956900e104326cef17f8111017eadb3eac2fd Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 29 Mar 2026 20:45:48 +0200 Subject: [PATCH] fix: eliminate first-paint flicker in landing handlebars --- .../web/src/components/landing/handlebars.tsx | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/apps/web/src/components/landing/handlebars.tsx b/apps/web/src/components/landing/handlebars.tsx index da0d895d..cfc688ce 100644 --- a/apps/web/src/components/landing/handlebars.tsx +++ b/apps/web/src/components/landing/handlebars.tsx @@ -1,6 +1,12 @@ "use client"; -import { type PropsWithChildren, useEffect, useRef, useState } from "react"; +import { + type PropsWithChildren, + useEffect, + useLayoutEffect, + useRef, + useState, +} from "react"; type HandlebarsProps = PropsWithChildren; @@ -31,7 +37,7 @@ export function Handlebars({ children }: HandlebarsProps) { initialPosition: 0, }); - useEffect(() => { + useLayoutEffect(() => { const el = containerRef.current; if (!el) return; @@ -106,9 +112,22 @@ export function Handlebars({ children }: HandlebarsProps) { }; }, []); - const leftGradientPercent = width > 0 ? (leftHandle / (width - 10)) * 100 : 0; - const rightGradientPercent = - width > 0 ? (rightHandle / (width + 10)) * 100 : 0; + const hasMeasuredWidth = width > 0; + const leftGradientPercent = hasMeasuredWidth + ? (leftHandle / (width - 10)) * 100 + : 0; + const rightGradientPercent = hasMeasuredWidth + ? (rightHandle / (width + 10)) * 100 + : 100; + const textMask = hasMeasuredWidth + ? `linear-gradient(90deg, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 0) ${leftGradientPercent}%, + rgba(0, 0, 0) ${leftGradientPercent}%, + rgba(0, 0, 0) ${rightGradientPercent}%, + rgba(255, 255, 255, 0) ${rightGradientPercent}%, + rgba(255, 255, 255, 0) 100%)` + : undefined; return (
@@ -135,9 +154,11 @@ export function Handlebars({ children }: HandlebarsProps) {
{ event.preventDefault(); @@ -156,13 +177,8 @@ export function Handlebars({ children }: HandlebarsProps) { {children}