···1111 const meta = usePlayerStore((s) => s.meta);
1212 const { disable } = useWatchPartyStore();
13131414- // Store the current meta to track changes
1515- const previousMetaRef = useRef<string | null>(null);
1414+ // Store the current base media to track changes
1515+ const previousBaseMediaRef = useRef<string | null>(null);
16161717- // Memoize the metaId calculation
1818- const metaId = useMemo(() => {
1717+ // Memoize the base media ID (without episode details for shows)
1818+ // This allows episode changes within the same show to keep the room active
1919+ const baseMediaId = useMemo(() => {
1920 if (!meta) return null;
20212121- return meta.type === "show"
2222- ? `${meta.type}-${meta.tmdbId}-s${meta.season?.tmdbId || "0"}-e${meta.episode?.tmdbId || "0"}`
2323- : `${meta.type}-${meta.tmdbId}`;
2222+ // For shows, only track the show ID, not the episode
2323+ // This allows episode navigation within the same show
2424+ return `${meta.type}-${meta.tmdbId}`;
2425 }, [meta]);
25262627 useEffect(() => {
2727- // If meta exists but has changed, reset watch party
2828+ // If base media has changed (different show/movie), reset watch party
2829 if (
2929- metaId &&
3030- previousMetaRef.current &&
3131- metaId !== previousMetaRef.current
3030+ baseMediaId &&
3131+ previousBaseMediaRef.current &&
3232+ baseMediaId !== previousBaseMediaRef.current
3233 ) {
3334 // eslint-disable-next-line no-console
3434- console.log("Media changed, disabling watch party:", {
3535- previous: previousMetaRef.current,
3636- current: metaId,
3535+ console.log("Base media changed, disabling watch party:", {
3636+ previous: previousBaseMediaRef.current,
3737+ current: baseMediaId,
3738 });
3839 disable();
3940 }
40414141- // Update the ref with current meta
4242- previousMetaRef.current = metaId;
4242+ // Update the ref with current base media
4343+ previousBaseMediaRef.current = baseMediaId;
43444445 // Also reset when component unmounts (player exited)
4546 return () => {
4647 disable();
4748 };
4848- }, [metaId, disable]);
4949+ }, [baseMediaId, disable]);
49505051 return null; // This component doesn't render anything
5152}