Fix sidebar layout shift on load

This commit is contained in:
Kalle
2026-03-08 12:40:07 +02:00
parent ae511557bf
commit 6477307b2e
2 changed files with 14 additions and 17 deletions

View File

@@ -121,7 +121,12 @@ export function ListLink({
{subtitle || badge ? (
<div className={styles.listLinkSubtitleRow}>
{subtitle ? (
<span className={styles.listLinkSubtitle}>{subtitle}</span>
<span
className={styles.listLinkSubtitle}
suppressHydrationWarning
>
{subtitle}
</span>
) : null}
{typeof badge === "string" ? (
<span

View File

@@ -2,7 +2,6 @@ import { isToday, isTomorrow } from "date-fns";
import * as React from "react";
import { useTranslation } from "react-i18next";
import type { SidebarStream } from "~/features/core/streams/streams.server";
import { useIsMounted } from "~/hooks/useIsMounted";
import type { LanguageCode } from "~/modules/i18n/config";
import { databaseTimestampToDate, formatDistanceToNow } from "~/utils/dates";
import { navIconUrl } from "~/utils/urls";
@@ -19,7 +18,6 @@ export function StreamListItems({
onClick?: () => void;
}) {
const { t, i18n } = useTranslation(["front"]);
const isMounted = useIsMounted();
const formatRelativeDate = (timestamp: number) => {
const date = new Date(timestamp * 1000);
@@ -60,7 +58,7 @@ export function StreamListItems({
const prevIsLive =
prevStream &&
databaseTimestampToDate(prevStream.startsAt).getTime() <= Date.now();
const showUpcomingDivider = isMounted && isUpcoming && prevIsLive;
const showUpcomingDivider = isUpcoming && prevIsLive;
return (
<React.Fragment key={stream.id}>
@@ -85,22 +83,16 @@ export function StreamListItems({
</span>
) : stream.subtitle ? (
stream.subtitle
) : isMounted ? (
isUpcoming ? (
formatRelativeDate(stream.startsAt)
) : (
formatDistanceToNow(startsAtDate, {
addSuffix: true,
language: i18n.language as LanguageCode,
})
)
) : isUpcoming ? (
formatRelativeDate(stream.startsAt)
) : (
""
formatDistanceToNow(startsAtDate, {
addSuffix: true,
language: i18n.language as LanguageCode,
})
)
}
badge={
isMounted && !isUpcoming ? "LIVE" : streamTierBadge(stream)
}
badge={!isUpcoming ? "LIVE" : streamTierBadge(stream)}
onClick={onClick}
>
{stream.name}