Skip to content

Commit 0e7d129

Browse files
Potential fix for pull request finding 'CodeQL / DOM text reinterpreted as HTML'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: ˚ʚ 𝒩❀𝓃𝒶𝓂𝑒 ɞ˚ <156847032+thenoname-gurl@users.noreply.github.com>
1 parent d079b06 commit 0e7d129

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

frontend/app/dashboard/settings/page.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

33
import { PanelHeader } from "@/components/panel/header"
4-
import { useEffect, useRef, useState } from "react"
4+
import { useEffect, useMemo, useRef, useState } from "react"
55
import { apiFetch } from "@/lib/api-client"
66
import { API_ENDPOINTS } from "@/lib/panel-config"
77
import { useAuth } from "@/hooks/useAuth"
@@ -1078,12 +1078,21 @@ export default function SettingsPage() {
10781078
const [videoDevices, setVideoDevices] = useState<MediaDeviceInfo[]>([])
10791079
const [selectedCameraId, setSelectedCameraId] = useState<string | null>(null)
10801080
const [capturedSelfie, setCapturedSelfie] = useState<Blob | null>(null)
1081-
const [capturedSelfieUrl, setCapturedSelfieUrl] = useState<string | null>(null)
1082-
const safeCapturedSelfieUrl =
1083-
capturedSelfieUrl && capturedSelfieUrl.startsWith("blob:") ? capturedSelfieUrl : ""
1081+
const previewSelfieUrl = useMemo(() => {
1082+
if (!capturedSelfie) return ""
1083+
return URL.createObjectURL(capturedSelfie)
1084+
}, [capturedSelfie])
10841085
const [cameraError, setCameraError] = useState<string | null>(null)
10851086
const [selfieMessage, setSelfieMessage] = useState<string | null>(null)
10861087
const [selfieLoading, setSelfieLoading] = useState(false)
1088+
useEffect(() => {
1089+
return () => {
1090+
if (previewSelfieUrl) {
1091+
URL.revokeObjectURL(previewSelfieUrl)
1092+
}
1093+
}
1094+
}, [previewSelfieUrl])
1095+
10871096
const videoRef = useRef<HTMLVideoElement | null>(null)
10881097
const canvasRef = useRef<HTMLCanvasElement | null>(null)
10891098

@@ -1964,15 +1973,10 @@ export default function SettingsPage() {
19641973
onChange={(e) => {
19651974
const file = e.target.files?.[0]
19661975
if (!file) return
1967-
if (capturedSelfieUrl) {
1968-
URL.revokeObjectURL(capturedSelfieUrl)
1969-
}
19701976
if (cameraStream) {
19711977
stopCamera()
19721978
}
1973-
const url = URL.createObjectURL(file)
19741979
setCapturedSelfie(file)
1975-
setCapturedSelfieUrl(url)
19761980
setCameraError(null)
19771981
setCameraActive(false)
19781982
}}
@@ -2016,7 +2020,7 @@ export default function SettingsPage() {
20162020
{capturedSelfie && (
20172021
<div className="space-y-3">
20182022
<img
2019-
src={safeCapturedSelfieUrl}
2023+
src={previewSelfieUrl}
20202024
alt="Captured selfie preview"
20212025
className="h-64 w-full rounded-lg object-cover"
20222026
/>

0 commit comments

Comments
 (0)