refactor: remove redundant fatalError ref, use state directly in handleLeave

This commit is contained in:
Igor Loskutov
2026-02-05 22:06:15 -05:00
parent f4803c0d76
commit 6c88e05423

View File

@@ -254,7 +254,6 @@ export default function DailyRoom({ meeting, room }: DailyRoomProps) {
const startRecordingMutation = useMeetingStartRecording(); const startRecordingMutation = useMeetingStartRecording();
const [joinedMeeting, setJoinedMeeting] = useState<Meeting | null>(null); const [joinedMeeting, setJoinedMeeting] = useState<Meeting | null>(null);
const [fatalError, setFatalError] = useState<FatalError | null>(null); const [fatalError, setFatalError] = useState<FatalError | null>(null);
const fatalErrorRef = useRef<FatalError | null>(null);
// Generate deterministic instanceIds so all participants use SAME IDs // Generate deterministic instanceIds so all participants use SAME IDs
const cloudInstanceId = parseNonEmptyString(meeting.id); const cloudInstanceId = parseNonEmptyString(meeting.id);
@@ -302,16 +301,15 @@ export default function DailyRoom({ meeting, room }: DailyRoomProps) {
const handleLeave = useCallback(() => { const handleLeave = useCallback(() => {
// If a fatal error occurred, don't redirect — let the error UI show // If a fatal error occurred, don't redirect — let the error UI show
if (fatalErrorRef.current) return; if (fatalError) return;
router.push("/browse"); router.push("/browse");
}, [router]); }, [router, fatalError]);
const handleError = useCallback((ev: DailyEventObjectFatalError) => { const handleError = useCallback((ev: DailyEventObjectFatalError) => {
const error: FatalError = { const error: FatalError = {
type: ev.error?.type ?? "unknown", type: ev.error?.type ?? "unknown",
message: ev.errorMsg, message: ev.errorMsg,
}; };
fatalErrorRef.current = error;
setFatalError(error); setFatalError(error);
}, []); }, []);