fix: stop artwork/background flashing when pages open
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
- disable router view transitions (they cross-faded through a black frame) - keep the last app backdrop instead of clearing it to nothing on navigation - drop opacity fade-in on cards, hero and detail artwork: cached images must be visible on the first paint, not fade from empty - keep the hero slide mounted so the old image remains until the new one loads - ambient backdrop falls back to the poster BlurHash for poster-only items - show the router loader only after 250ms so fast navigations don't blink
This commit is contained in:
1 parent
4c9dd86962
commit
b00f93d262
10 files changed
+51
-46
No files matched your search
@@ -5,15 +5,20 @@ import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import BlurhashCanvas from "../blurhash-canvas";
|
||||
|
||||
export default function Backdrop() {
|
||||
// const [backdropLoading, setBackdropLoading] = useState(true);
|
||||
|
||||
const { backdropHash } = useBackdropStore(
|
||||
useShallow((state) => ({
|
||||
backdropHash: state.backdropHash,
|
||||
})),
|
||||
);
|
||||
|
||||
if (!backdropHash) {
|
||||
// Routes clear the backdrop when they mount ("") and some set it later.
|
||||
// Keep the last non-empty hash so the app background never blanks out
|
||||
// (which looked like a flash on every page open).
|
||||
const lastHash = React.useRef<string | undefined>(undefined);
|
||||
if (backdropHash) lastHash.current = backdropHash;
|
||||
const hash = backdropHash || lastHash.current;
|
||||
|
||||
if (!hash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,16 +27,16 @@ export default function Backdrop() {
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
key={backdropHash}
|
||||
key={hash}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{
|
||||
duration: 2,
|
||||
duration: 0.45,
|
||||
ease: "easeInOut",
|
||||
}}
|
||||
className="app-backdrop-container"
|
||||
>
|
||||
<BlurhashCanvas
|
||||
blurhashString={backdropHash}
|
||||
blurhashString={hash}
|
||||
width={300}
|
||||
height={150}
|
||||
canvasProps={{
|
||||
@@ -47,4 +52,4 @@ export default function Backdrop() {
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: all $transition-time-fast;
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: 0;
|
||||
|
||||
@@ -107,7 +107,7 @@ const CardContent = ({
|
||||
? getTypeIcon(overrideIcon)
|
||||
: getTypeIcon(item.Type ?? "universal")}
|
||||
</div>
|
||||
{inView && image && (
|
||||
{image && (
|
||||
<img
|
||||
alt={item.Name ?? "blink"}
|
||||
src={
|
||||
@@ -128,14 +128,9 @@ const CardContent = ({
|
||||
style={{
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
opacity: 0,
|
||||
display: "block",
|
||||
transition: "opacity 0.3s ease-in-out",
|
||||
}}
|
||||
loading="lazy"
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className="card-image"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -21,10 +21,12 @@ interface ItemBackdropProps {
|
||||
const MotionImg = motion.img;
|
||||
|
||||
const animationProps = {
|
||||
initial: { opacity: 0 },
|
||||
// Do not fade in from black on every navigation: cached artwork should be
|
||||
// visible immediately (a fade here reads as a flash).
|
||||
initial: { opacity: 1 },
|
||||
animate: { opacity: 1 },
|
||||
exit: { opacity: 0 },
|
||||
transition: { duration: 0.5 },
|
||||
transition: { duration: 0.3 },
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -113,6 +115,9 @@ export function ItemBackdrop({
|
||||
alt={alt}
|
||||
src={src}
|
||||
className={className ?? "item-hero-backdrop"}
|
||||
ref={(el) => {
|
||||
if (el?.complete && el.naturalWidth > 0) el.style.opacity = "1";
|
||||
}}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
onLoad?.(e);
|
||||
|
||||
@@ -101,8 +101,6 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
opacity: 0;
|
||||
transition: opacity $transition-time-default;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
@@ -77,9 +77,6 @@ const ItemHeader = ({
|
||||
tag: logoTag,
|
||||
})
|
||||
}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className="item-hero-logo"
|
||||
/>
|
||||
) : (
|
||||
@@ -143,9 +140,6 @@ const ItemHeader = ({
|
||||
},
|
||||
)
|
||||
}
|
||||
onLoad={(e) => {
|
||||
e.currentTarget.style.opacity = "1";
|
||||
}}
|
||||
className="item-hero-image"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -12,10 +12,8 @@ $cardWidth: 18%;
|
||||
grid-template-columns: $cardWidth 1fr;
|
||||
grid-template-rows: 1fr auto;
|
||||
&-image {
|
||||
opacity: 0;
|
||||
width: 100%;
|
||||
object-fit: contain;
|
||||
transition: opacity $transition-time-default;
|
||||
&-container {
|
||||
height: fit-content;
|
||||
max-height: 100%;
|
||||
@@ -47,8 +45,6 @@ $cardWidth: 18%;
|
||||
&-logo {
|
||||
max-width: 34rem;
|
||||
max-height: 10rem;
|
||||
opacity: 0;
|
||||
transition: opacity $transition-time-default;
|
||||
object-position: bottom;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
@@ -74,11 +70,9 @@ $cardWidth: 18%;
|
||||
height: 100vh;
|
||||
object-fit: cover;
|
||||
object-position: top;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
transition: opacity $transition-time-default;
|
||||
&-container {
|
||||
filter: brightness(0.8);
|
||||
position: absolute;
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import { useRouterState } from "@tanstack/react-router";
|
||||
import React from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
/** Only show the full-screen loader for genuinely slow navigations. */
|
||||
const SHOW_DELAY_MS = 250;
|
||||
|
||||
export default function RouterLoading() {
|
||||
const routeLoading = useRouterState().isLoading;
|
||||
if (!routeLoading) return null;
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!routeLoading) {
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
const timer = setTimeout(() => setVisible(true), SHOW_DELAY_MS);
|
||||
return () => clearTimeout(timer);
|
||||
}, [routeLoading]);
|
||||
|
||||
if (!visible) return null;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
@@ -21,4 +35,4 @@ export default function RouterLoading() {
|
||||
<CircularProgress size={72} thickness={2} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -43,7 +43,7 @@ const router = createRouter({
|
||||
},
|
||||
defaultPreload: false,
|
||||
defaultPreloadStaleTime: 0,
|
||||
defaultViewTransition: true,
|
||||
defaultViewTransition: false,
|
||||
scrollRestoration: true,
|
||||
scrollRestorationBehavior: "auto",
|
||||
});
|
||||
|
||||
@@ -142,19 +142,20 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
|
||||
const setBackdropForItem = useCallback(
|
||||
(item: BaseItemDto) => {
|
||||
if (item?.ParentBackdropImageTags) {
|
||||
setBackdrop(
|
||||
item.ImageBlurHashes?.Backdrop?.[item.ParentBackdropImageTags[0]],
|
||||
);
|
||||
} else {
|
||||
if (!item?.BackdropImageTags) {
|
||||
setBackdrop(undefined);
|
||||
return;
|
||||
}
|
||||
setBackdrop(
|
||||
item.ImageBlurHashes?.Backdrop?.[item.BackdropImageTags[0]],
|
||||
);
|
||||
// Use the wide artwork when present, otherwise the poster's BlurHash as
|
||||
// an ambient background (poster-only items would otherwise leave it dark).
|
||||
const backdropTag =
|
||||
item.ParentBackdropImageTags?.[0] ?? item.BackdropImageTags?.[0];
|
||||
if (backdropTag) {
|
||||
setBackdrop(item.ImageBlurHashes?.Backdrop?.[backdropTag] ?? undefined);
|
||||
return;
|
||||
}
|
||||
const primaryTag = item.ImageTags?.Primary;
|
||||
setBackdrop(
|
||||
primaryTag
|
||||
? (item.ImageBlurHashes?.Primary?.[primaryTag] ?? undefined)
|
||||
: undefined,
|
||||
);
|
||||
},
|
||||
[setBackdrop],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user