mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-06 23:27:36 +03:00
Miscellaneous fixes (#22762)
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
This commit is contained in:
parent
9ba81d6dc8
commit
d8c35d5a0f
@ -2,7 +2,7 @@ import type { FieldPathList, FieldProps } from "@rjsf/utils";
|
|||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
function formatYaml(value: unknown): string {
|
function formatYaml(value: unknown): string {
|
||||||
if (
|
if (
|
||||||
@ -54,10 +54,14 @@ export function DictAsYamlField(props: FieldProps) {
|
|||||||
|
|
||||||
const [text, setText] = useState(() => formatYaml(formData));
|
const [text, setText] = useState(() => formatYaml(formData));
|
||||||
const [error, setError] = useState<string>();
|
const [error, setError] = useState<string>();
|
||||||
|
const focusedRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setText(formatYaml(formData));
|
// Only sync from external formData changes, not our own onChange
|
||||||
setError(undefined);
|
if (!focusedRef.current) {
|
||||||
|
setText(formatYaml(formData));
|
||||||
|
setError(undefined);
|
||||||
|
}
|
||||||
}, [formData]);
|
}, [formData]);
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
@ -73,8 +77,13 @@ export function DictAsYamlField(props: FieldProps) {
|
|||||||
[onChange, fieldPath],
|
[onChange, fieldPath],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleFocus = useCallback(() => {
|
||||||
|
focusedRef.current = true;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleBlur = useCallback(
|
const handleBlur = useCallback(
|
||||||
(_e: React.FocusEvent<HTMLTextAreaElement>) => {
|
(_e: React.FocusEvent<HTMLTextAreaElement>) => {
|
||||||
|
focusedRef.current = false;
|
||||||
// Reformat on blur if valid
|
// Reformat on blur if valid
|
||||||
const { value } = parseYaml(text);
|
const { value } = parseYaml(text);
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
@ -101,6 +110,7 @@ export function DictAsYamlField(props: FieldProps) {
|
|||||||
placeholder={"key: value"}
|
placeholder={"key: value"}
|
||||||
rows={Math.max(3, text.split("\n").length + 1)}
|
rows={Math.max(3, text.split("\n").length + 1)}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
onFocus={handleFocus}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
/>
|
/>
|
||||||
{error && <p className="text-xs text-destructive">{error}</p>}
|
{error && <p className="text-xs text-destructive">{error}</p>}
|
||||||
|
|||||||
@ -195,6 +195,7 @@ export default function LivePlayer({
|
|||||||
}, [preferredLiveMode]);
|
}, [preferredLiveMode]);
|
||||||
|
|
||||||
const [key, setKey] = useState(0);
|
const [key, setKey] = useState(0);
|
||||||
|
const prevStreamNameRef = useRef(streamName);
|
||||||
|
|
||||||
const resetPlayer = () => {
|
const resetPlayer = () => {
|
||||||
setLiveReady(false);
|
setLiveReady(false);
|
||||||
@ -202,8 +203,11 @@ export default function LivePlayer({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (streamName) {
|
if (prevStreamNameRef.current !== streamName) {
|
||||||
resetPlayer();
|
prevStreamNameRef.current = streamName;
|
||||||
|
if (streamName) {
|
||||||
|
resetPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [streamName]);
|
}, [streamName]);
|
||||||
|
|
||||||
|
|||||||
@ -81,6 +81,7 @@ function MSEPlayer({
|
|||||||
const wsRef = useRef<WebSocket | null>(null);
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
const reconnectTIDRef = useRef<number | null>(null);
|
const reconnectTIDRef = useRef<number | null>(null);
|
||||||
const intentionalDisconnectRef = useRef<boolean>(false);
|
const intentionalDisconnectRef = useRef<boolean>(false);
|
||||||
|
const onCloseRef = useRef<(() => void) | null>(null);
|
||||||
const ondataRef = useRef<((data: ArrayBufferLike) => void) | null>(null);
|
const ondataRef = useRef<((data: ArrayBufferLike) => void) | null>(null);
|
||||||
const onmessageRef = useRef<{
|
const onmessageRef = useRef<{
|
||||||
[key: string]: (msg: { value: string; type: string }) => void;
|
[key: string]: (msg: { value: string; type: string }) => void;
|
||||||
@ -167,6 +168,8 @@ function MSEPlayer({
|
|||||||
wsRef.current = new WebSocket(wsURL);
|
wsRef.current = new WebSocket(wsURL);
|
||||||
wsRef.current.binaryType = "arraybuffer";
|
wsRef.current.binaryType = "arraybuffer";
|
||||||
wsRef.current.addEventListener("open", onOpen);
|
wsRef.current.addEventListener("open", onOpen);
|
||||||
|
// Capture current onClose identity so removeEventListener can find it later
|
||||||
|
onCloseRef.current = onClose;
|
||||||
wsRef.current.addEventListener("close", onClose);
|
wsRef.current.addEventListener("close", onClose);
|
||||||
// we know that these deps are correct
|
// we know that these deps are correct
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -200,20 +203,23 @@ function MSEPlayer({
|
|||||||
intentionalDisconnectRef.current = true;
|
intentionalDisconnectRef.current = true;
|
||||||
setWsState(WebSocket.CLOSED);
|
setWsState(WebSocket.CLOSED);
|
||||||
|
|
||||||
// Remove event listeners to prevent them firing during close
|
// Remove event listeners to prevent them firing during close.
|
||||||
|
// Use onCloseRef to remove the exact function that was attached in onConnect,
|
||||||
|
// since onClose may have been recreated by React since then.
|
||||||
try {
|
try {
|
||||||
ws.removeEventListener("open", onOpen);
|
ws.removeEventListener("open", onOpen);
|
||||||
ws.removeEventListener("close", onClose);
|
if (onCloseRef.current) {
|
||||||
|
ws.removeEventListener("close", onCloseRef.current);
|
||||||
|
onCloseRef.current = null;
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore errors removing listeners
|
// Ignore errors removing listeners
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only call close() if the socket is OPEN or CLOSING
|
// Close the socket in any non-CLOSED state, including CONNECTING.
|
||||||
// For CONNECTING or CLOSED sockets, just let it die
|
// A CONNECTING socket that is not closed will complete its handshake
|
||||||
if (
|
// and remain open, leaking a browser connection.
|
||||||
currentReadyState === WebSocket.OPEN ||
|
if (currentReadyState !== WebSocket.CLOSED) {
|
||||||
currentReadyState === WebSocket.CLOSING
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
ws.close();
|
ws.close();
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user