Fix KinescopePlayer SSR crash on direct page load
The @kinescope/react-kinescope-player library accesses browser APIs (window/document) during server-side rendering. In Next.js App Router, client components are SSR-rendered on full page loads (direct URL, refresh) but not on RSC navigations. This caused a 500 error for all lessons with a kinescopeId when accessed directly. Fix: defer rendering KinescopeReactPlayer until after mount with useEffect + useState(false), so it only runs in the browser.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import KinescopeReactPlayer from "@kinescope/react-kinescope-player";
|
||||
|
||||
interface Props {
|
||||
@@ -8,14 +9,19 @@ interface Props {
|
||||
}
|
||||
|
||||
export function KinescopePlayer({ videoId, poster }: Props) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
useEffect(() => setMounted(true), []);
|
||||
|
||||
return (
|
||||
<div className="w-full aspect-video" style={{ border: "2px solid var(--border)" }}>
|
||||
<KinescopeReactPlayer
|
||||
videoId={videoId}
|
||||
width="100%"
|
||||
height="100%"
|
||||
poster={poster}
|
||||
/>
|
||||
{mounted && (
|
||||
<KinescopeReactPlayer
|
||||
videoId={videoId}
|
||||
width="100%"
|
||||
height="100%"
|
||||
poster={poster}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user