fix: series page not showing correct bg

This commit is contained in:
--remove-section committed 2026-01-09 21:46:57 +05:30
1 parent 8519c12c45
commit 0883cb0fe1
4 files changed
+50 -19

No files matched your search

+33 -13
View File
@@ -1,4 +1,5 @@
import {
AnimatePresence,
type HTMLMotionProps,
motion,
useScroll,
@@ -17,6 +18,15 @@ interface ItemBackdropProps {
motionProps?: HTMLMotionProps<"img">;
}
const MotionImg = motion.img;
const animationProps = {
initial: { opacity: 0 },
animate: { opacity: 1 },
exit: { opacity: 0 },
transition: { duration: 0.5 },
};
/**
* ItemBackdrop delays applying motion-driven parallax until after mount
* to avoid hydration timing errors ("Target ref is defined but not hydrated").
@@ -24,7 +34,7 @@ interface ItemBackdropProps {
* attached, it renders a static img to prevent motion from touching an
* unhydrated DOM node.
*/
function ItemBackdropContent({
const ItemBackdropContent = React.memo(function ItemBackdropContent({
targetRef,
src,
alt,
@@ -47,19 +57,18 @@ function ItemBackdropContent({
});
const y = useTransform(scrollYProgress, [0, 1], [-distance, distance]);
return (
<motion.img
<MotionImg
alt={alt}
src={src}
className={className ?? "item-hero-backdrop"}
onLoad={(e) => {
e.currentTarget.style.opacity = "1";
onLoad?.(e);
}}
style={{ y }}
{...motionProps}
/>
);
}
});
export function ItemBackdrop({
targetRef,
@@ -90,6 +99,14 @@ export function ItemBackdrop({
return () => cancelAnimationFrame(raf);
}, [targetRef, ready]);
const finalMotionProps = React.useMemo(
() => ({
...animationProps,
...motionProps,
}),
[motionProps],
);
if (!ready) {
return (
<img
@@ -105,15 +122,18 @@ export function ItemBackdrop({
}
return (
<ItemBackdropContent
targetRef={targetRef}
src={src}
alt={alt}
distance={distance}
className={className}
onLoad={onLoad}
motionProps={motionProps}
/>
<AnimatePresence>
<ItemBackdropContent
key={src}
targetRef={targetRef}
src={src}
alt={alt}
distance={distance}
className={className}
onLoad={onLoad}
motionProps={finalMotionProps}
/>
</AnimatePresence>
);
}
+8 -5
View File
@@ -35,6 +35,7 @@ interface ItemHeaderProps {
mediaQualityInfo?: MediaQualityInfo;
scrollTargetRef?: RefObject<HTMLDivElement | null>;
children?: ReactNode;
backdropSrc?: string | null;
}
const ItemHeader = ({
@@ -43,6 +44,7 @@ const ItemHeader = ({
mediaQualityInfo,
scrollTargetRef,
children,
backdropSrc,
}: ItemHeaderProps) => {
const isEpisode = item.Type === "Episode";
const backdropTag =
@@ -61,7 +63,7 @@ const ItemHeader = ({
const logoId =
isEpisode && parentLogoImageTag ? (item.SeriesId ?? item.Id) : item.Id;
const LogoOrTitle = () =>
const logo =
logoTag ? (
<img
alt={item.Name ?? ""}
@@ -93,14 +95,15 @@ const ItemHeader = ({
targetRef={scrollTargetRef}
alt={item.Name ?? ""}
backdropSrc={
backdropTag
backdropSrc ??
(backdropTag
? api &&
getImageUrlsApi(api).getItemImageUrlById(
backdropId ?? "",
"Backdrop",
{ tag: backdropTag },
)
: undefined
: undefined)
}
fallbackSrc={heroBg}
/>
@@ -156,10 +159,10 @@ const ItemHeader = ({
width: "fit-content",
}}
>
<LogoOrTitle />
{logo}
</Link>
) : (
<LogoOrTitle />
logo
)}
{isEpisode && (
<Typography mb={2} fontWeight={200} variant="h4">
@@ -75,6 +75,9 @@ $cardWidth: 18%;
object-fit: cover;
object-position: top;
opacity: 0;
position: absolute;
top: 0;
left: 0;
transition: opacity $transition-time-default;
&-container {
filter: brightness(0.8);
+6 -1
View File
@@ -303,7 +303,12 @@ function SeriesTitlePage() {
className="scrollY padded-top flex flex-column item item-series"
ref={containerRef}
>
<ItemHeader item={item.data} api={api} scrollTargetRef={containerRef}>
<ItemHeader
item={item.data}
api={api}
scrollTargetRef={containerRef}
backdropSrc={backdropImage.url}
>
<div className="item-hero-buttons-container">
<div
className="flex flex-row"