Spaces:
Sleeping
Sleeping
vatche.thorossian OpenAI Codex commited on
Commit ·
b5ee86a
1
Parent(s): 52ddaed
Fix uploaded screenshot URL cleanup
Browse filesUse a ref-backed object URL cleanup path so uploaded screenshot previews are revoked even when an upload fails before React re-renders.
Co-authored-by: OpenAI Codex <codex@openai.com>
- buglens-ui/buglens-app.jsx +12 -7
buglens-ui/buglens-app.jsx
CHANGED
|
@@ -221,15 +221,19 @@ function App() {
|
|
| 221 |
const [toasts, push] = useToasts();
|
| 222 |
const timers = React.useRef([]);
|
| 223 |
const reqRef = React.useRef(0); // monotonic token so only the latest request wins
|
|
|
|
| 224 |
|
| 225 |
const clearTimers = () => { timers.current.forEach(clearTimeout); timers.current = []; };
|
| 226 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
// Gallery example: fetched from the mock backend by id.
|
| 229 |
const pick = (id) => {
|
| 230 |
clearTimers();
|
| 231 |
-
|
| 232 |
-
setShotUrl(null);
|
| 233 |
setUploadName("");
|
| 234 |
setActiveId(id);
|
| 235 |
setReport(null);
|
|
@@ -260,8 +264,10 @@ function App() {
|
|
| 260 |
return;
|
| 261 |
}
|
| 262 |
clearTimers();
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
| 265 |
setUploadName(file.name);
|
| 266 |
setActiveId(null);
|
| 267 |
setReport(null);
|
|
@@ -305,8 +311,7 @@ function App() {
|
|
| 305 |
const reset = () => {
|
| 306 |
clearTimers();
|
| 307 |
reqRef.current++; // invalidate any in-flight request
|
| 308 |
-
|
| 309 |
-
setShotUrl(null);
|
| 310 |
setUploadName("");
|
| 311 |
setView("idle");
|
| 312 |
setActiveId(null);
|
|
|
|
| 221 |
const [toasts, push] = useToasts();
|
| 222 |
const timers = React.useRef([]);
|
| 223 |
const reqRef = React.useRef(0); // monotonic token so only the latest request wins
|
| 224 |
+
const shotUrlRef = React.useRef(null);
|
| 225 |
|
| 226 |
const clearTimers = () => { timers.current.forEach(clearTimeout); timers.current = []; };
|
| 227 |
+
const clearShot = () => {
|
| 228 |
+
if (shotUrlRef.current) URL.revokeObjectURL(shotUrlRef.current);
|
| 229 |
+
shotUrlRef.current = null;
|
| 230 |
+
setShotUrl(null);
|
| 231 |
+
};
|
| 232 |
|
| 233 |
// Gallery example: fetched from the mock backend by id.
|
| 234 |
const pick = (id) => {
|
| 235 |
clearTimers();
|
| 236 |
+
clearShot();
|
|
|
|
| 237 |
setUploadName("");
|
| 238 |
setActiveId(id);
|
| 239 |
setReport(null);
|
|
|
|
| 264 |
return;
|
| 265 |
}
|
| 266 |
clearTimers();
|
| 267 |
+
clearShot();
|
| 268 |
+
const nextShotUrl = URL.createObjectURL(file);
|
| 269 |
+
shotUrlRef.current = nextShotUrl;
|
| 270 |
+
setShotUrl(nextShotUrl);
|
| 271 |
setUploadName(file.name);
|
| 272 |
setActiveId(null);
|
| 273 |
setReport(null);
|
|
|
|
| 311 |
const reset = () => {
|
| 312 |
clearTimers();
|
| 313 |
reqRef.current++; // invalidate any in-flight request
|
| 314 |
+
clearShot();
|
|
|
|
| 315 |
setUploadName("");
|
| 316 |
setView("idle");
|
| 317 |
setActiveId(null);
|