perf(startup): instant splash, cached home and non-blocking auth
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
Renders a static branded splash immediately, restores the last user/API session from disk, hydrates home/library queries from localStorage, shows a home skeleton while the first request runs, drops blocking auth network checks, and redirects a streamless /player to home.
This commit is contained in:
1 parent
b1d9b40def
commit
205b655d00
12 files changed
+424
-158
No files matched your search
@@ -26,6 +26,7 @@ import Backdrop from "@/components/backdrop";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import OverlayScrollbar from "@/components/overlayScrollbar";
|
||||
import PlaybackSync from "@/components/playback/PlaybackSync";
|
||||
import SplashHider from "@/components/splash";
|
||||
import RemoteControlDialog from "@/components/remoteControl";
|
||||
import RouterLoading from "@/components/routerLoading";
|
||||
import Search from "@/components/search";
|
||||
@@ -50,6 +51,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
||||
<ThemeProvider theme={theme}>
|
||||
<SnackbarProvider maxSnack={5}>
|
||||
<CssBaseline />
|
||||
<SplashHider />
|
||||
{/* <NProgress /> */}
|
||||
|
||||
<RouterLoading />
|
||||
|
||||
+26
-83
@@ -1,14 +1,13 @@
|
||||
import { getDefaultServer, getServer } from "@/utils/storage/servers";
|
||||
import { delUser, getUser } from "@/utils/storage/user";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUser } from "@/utils/storage/user";
|
||||
import { createFileRoute, redirect } from "@tanstack/react-router";
|
||||
|
||||
const isAuthError = (error: unknown) => {
|
||||
const status = (error as { response?: { status?: number } })?.response?.status;
|
||||
return status === 401 || status === 403;
|
||||
};
|
||||
|
||||
/**
|
||||
* Session bootstrap is deliberately local-only: reading the Tauri store is
|
||||
* quick, while network verification would block the first render. The token
|
||||
* is validated in the background by ProviderWrapper, which redirects to the
|
||||
* login page on a real 401/403 without punishing transient network errors.
|
||||
*/
|
||||
export const Route = createFileRoute("/_api")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
const isAuthPage =
|
||||
@@ -18,86 +17,30 @@ export const Route = createFileRoute("/_api")({
|
||||
|
||||
if (!context.api) {
|
||||
const currentServerId = await getDefaultServer();
|
||||
if (currentServerId) {
|
||||
const currentServer = await getServer(currentServerId);
|
||||
if (currentServer?.address) {
|
||||
const apiTemp = context.jellyfinSDK.createApi(
|
||||
currentServer?.address,
|
||||
undefined,
|
||||
);
|
||||
try {
|
||||
await getSystemApi(apiTemp).getPingSystem();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw redirect({
|
||||
to: "/error/$code",
|
||||
params: {
|
||||
code: "101",
|
||||
},
|
||||
});
|
||||
}
|
||||
const userOnDisk = await getUser();
|
||||
if (userOnDisk) {
|
||||
if (location.pathname !== "/login/manual") {
|
||||
const apiTemp = context.jellyfinSDK.createApi(
|
||||
currentServer?.address,
|
||||
userOnDisk.AccessToken,
|
||||
);
|
||||
try {
|
||||
await getUserApi(apiTemp).getCurrentUser();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (isAuthError(error)) {
|
||||
await delUser();
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: {
|
||||
redirect: location.href,
|
||||
},
|
||||
});
|
||||
}
|
||||
// Transient network failure: keep the saved session
|
||||
// instead of logging the user out.
|
||||
}
|
||||
}
|
||||
context.createApi(currentServer?.address, userOnDisk.AccessToken);
|
||||
} else {
|
||||
context.createApi(currentServer?.address, undefined); // Creates Api
|
||||
if (!isAuthPage) {
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: { redirect: location.href },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!currentServerId) {
|
||||
if (!isAuthPage) throw redirect({ to: "/setup/server/add" });
|
||||
return;
|
||||
}
|
||||
} else if (context.api) {
|
||||
// The API was created from a token stored on disk. The token can be
|
||||
// revoked (logged out everywhere / server reset); verify it and send
|
||||
// the user back to the login page instead of leaving a broken page.
|
||||
if (!context.api.accessToken && !isAuthPage) {
|
||||
|
||||
const currentServer = await getServer(currentServerId);
|
||||
if (!currentServer?.address) {
|
||||
if (!isAuthPage) throw redirect({ to: "/setup/server/add" });
|
||||
return;
|
||||
}
|
||||
|
||||
const userOnDisk = await getUser();
|
||||
context.createApi(currentServer.address, userOnDisk?.AccessToken);
|
||||
if (!userOnDisk?.AccessToken && !isAuthPage) {
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: { redirect: location.href },
|
||||
});
|
||||
}
|
||||
if (context.api.accessToken && !isAuthPage) {
|
||||
try {
|
||||
await getUserApi(context.api).getCurrentUser();
|
||||
} catch (error) {
|
||||
console.error("Could not verify the stored access token", error);
|
||||
if (isAuthError(error)) {
|
||||
await delUser();
|
||||
context.createApi(context.api.basePath, undefined);
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: { redirect: location.href },
|
||||
});
|
||||
}
|
||||
// Network hiccup: do not throw the user out of the app.
|
||||
}
|
||||
}
|
||||
} else if (!context.api.accessToken && !isAuthPage) {
|
||||
throw redirect({
|
||||
to: "/login/manual",
|
||||
search: { redirect: location.href },
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -146,6 +146,101 @@ body.has-player-bar .home-sections {
|
||||
padding-bottom: 10rem;
|
||||
}
|
||||
|
||||
/* Instant frame while the first home request resolves or cache restores. */
|
||||
.home-skeleton {
|
||||
position: relative;
|
||||
height: calc(100vh - 16px);
|
||||
min-height: 560px;
|
||||
overflow: hidden;
|
||||
background:
|
||||
radial-gradient(
|
||||
circle at 75% 35%,
|
||||
rgb(80 80 105 / 0.28),
|
||||
transparent 55%
|
||||
),
|
||||
linear-gradient(135deg, #11131a 0%, #0a0b10 70%);
|
||||
}
|
||||
|
||||
.home-skeleton-copy {
|
||||
position: absolute;
|
||||
left: clamp(2rem, 5vw, 4.5rem);
|
||||
bottom: calc(var(--home-trending-space, 200px) + 3.5rem);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.9rem;
|
||||
width: min(42rem, 55%);
|
||||
}
|
||||
|
||||
.home-skeleton-pill,
|
||||
.home-skeleton-title,
|
||||
.home-skeleton-text,
|
||||
.home-skeleton-buttons,
|
||||
.home-skeleton-heading,
|
||||
.home-skeleton-cards span {
|
||||
display: block;
|
||||
border-radius: 12px;
|
||||
background: rgb(255 255 255 / 0.08);
|
||||
}
|
||||
|
||||
.home-skeleton-pill {
|
||||
width: 7em;
|
||||
height: 2.1em;
|
||||
}
|
||||
|
||||
.home-skeleton-title {
|
||||
width: 92%;
|
||||
height: clamp(2.4rem, 4vw, 4rem);
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.home-skeleton-text {
|
||||
width: 100%;
|
||||
height: 5.2rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.home-skeleton-buttons {
|
||||
width: 18rem;
|
||||
height: 3.1rem;
|
||||
border-radius: 999px;
|
||||
background: rgb(255 255 255 / 0.14);
|
||||
}
|
||||
|
||||
.home-skeleton-trending {
|
||||
position: absolute;
|
||||
left: clamp(2rem, 5vw, 4.5rem);
|
||||
right: clamp(2rem, 5vw, 4.5rem);
|
||||
bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.home-skeleton-heading {
|
||||
width: 8em;
|
||||
height: 1.4rem;
|
||||
margin-bottom: 0.9rem;
|
||||
}
|
||||
|
||||
.home-skeleton-cards {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.home-skeleton-cards span {
|
||||
flex: 0 0 auto;
|
||||
width: clamp(200px, 21vw, 300px);
|
||||
aspect-ratio: 16 / 9;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.home-skeleton-copy {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.home-skeleton-cards span {
|
||||
width: 42vw;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.home-header {
|
||||
.home-nav-link {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import React, { useCallback, useMemo } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import React, { useCallback, useEffect, useMemo } from "react";
|
||||
|
||||
import "./home.scss";
|
||||
|
||||
@@ -51,7 +51,7 @@ function Home() {
|
||||
}
|
||||
|
||||
function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
const libraries = useSuspenseQuery({
|
||||
const libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
const libs = await getUserViewApi(api).getUserViews({
|
||||
@@ -62,11 +62,11 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
const latestMedia = useSuspenseQuery(
|
||||
const latestMedia = useQuery(
|
||||
getLatestItemsQueryOptions(api, user.Id),
|
||||
);
|
||||
|
||||
const resumeItemsVideo = useSuspenseQuery({
|
||||
const resumeItemsVideo = useQuery({
|
||||
queryKey: ["home", "resume", "video"],
|
||||
queryFn: async () => {
|
||||
const resumeItems = await getLibraryApi(api).getResumeItems({
|
||||
@@ -80,7 +80,7 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
},
|
||||
});
|
||||
|
||||
const resumeItemsAudio = useSuspenseQuery({
|
||||
const resumeItemsAudio = useQuery({
|
||||
queryKey: ["home", "resume", "audio"],
|
||||
queryFn: async () => {
|
||||
const resumeItems = await getLibraryApi(api).getResumeItems({
|
||||
@@ -94,7 +94,7 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
},
|
||||
});
|
||||
|
||||
const upNextItems = useSuspenseQuery({
|
||||
const upNextItems = useQuery({
|
||||
queryKey: ["home", "upNext"],
|
||||
queryFn: async () => {
|
||||
const upNext = await getShowApi(api).getNextUp({
|
||||
@@ -178,6 +178,46 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
||||
?.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!import.meta.env.DEV) return;
|
||||
if (!libraries.data || !latestMedia.data) return;
|
||||
performance.mark("blink:home-ready");
|
||||
}, [libraries.data, latestMedia.data]);
|
||||
|
||||
// Render the frame immediately; only the expensive content waits for data.
|
||||
if (!libraries.data || !latestMedia.data) {
|
||||
return (
|
||||
<main className="home-cinema">
|
||||
<div className="home-frame">
|
||||
<HomeHeader
|
||||
libraries={libraries.data?.Items ?? []}
|
||||
onNewAndPopular={scrollToNewAndPopular}
|
||||
/>
|
||||
<section
|
||||
className="home-skeleton"
|
||||
aria-busy="true"
|
||||
aria-label="Loading home"
|
||||
>
|
||||
<div className="home-skeleton-copy">
|
||||
<span className="home-skeleton-pill" />
|
||||
<span className="home-skeleton-title" />
|
||||
<span className="home-skeleton-text" />
|
||||
<span className="home-skeleton-buttons" />
|
||||
</div>
|
||||
<div className="home-skeleton-trending">
|
||||
<span className="home-skeleton-heading" />
|
||||
<div className="home-skeleton-cards">
|
||||
{[0, 1, 2, 3].map((index) => (
|
||||
<span key={index} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="home-cinema">
|
||||
<div className="home-frame">
|
||||
|
||||
@@ -10,7 +10,7 @@ import "./videoPlayer.scss";
|
||||
|
||||
import { RepeatMode } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { createFileRoute, useRouter } from "@tanstack/react-router";
|
||||
import { createFileRoute, useNavigate, useRouter } from "@tanstack/react-router";
|
||||
import JASSUB from "jassub";
|
||||
import wasmUrl from "jassub/dist/wasm/jassub-worker.wasm?url"; // non-SIMD fallback
|
||||
import modernWasmUrl from "jassub/dist/wasm/jassub-worker-modern.wasm?url"; // SIMD
|
||||
@@ -82,6 +82,7 @@ function addSubtitleTrackToReactPlayer(
|
||||
|
||||
export function VideoPlayer() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const navigate = useNavigate();
|
||||
const { history } = useRouter();
|
||||
const player = useRef<HTMLVideoElement | null>(null);
|
||||
/** Re-apply the transfer/resume position until the HLS player stabilises. */
|
||||
@@ -599,6 +600,17 @@ export function VideoPlayer() {
|
||||
setError(e);
|
||||
}, []);
|
||||
|
||||
// A direct/reloaded /player route with no active stream must not trap the
|
||||
// user on an endless spinner.
|
||||
useEffect(() => {
|
||||
if (playbackStream) return;
|
||||
const timer = window.setTimeout(
|
||||
() => navigate({ to: "/home", replace: true }),
|
||||
250,
|
||||
);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [playbackStream, navigate]);
|
||||
|
||||
if (!playbackStream) {
|
||||
return (
|
||||
<div className="video-player">
|
||||
|
||||
Reference in new issue
Block a user