Commit ·
2496cac
1
Parent(s): 95fa2df
Fix fireRegen: clear+set pattern for Gradio 5 React .change()
Browse files
app.py
CHANGED
|
@@ -1531,14 +1531,32 @@ _GLOBAL_JS = """
|
|
| 1531 |
function fireRegen(slot_id, idx) {
|
| 1532 |
const hidden_id = 'regen_trigger_' + slot_id;
|
| 1533 |
const el = document.getElementById(hidden_id);
|
| 1534 |
-
if (!el) return;
|
| 1535 |
const input = el.querySelector('input, textarea');
|
| 1536 |
-
if (!input) return;
|
| 1537 |
-
|
| 1538 |
-
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1542 |
// Update status label
|
| 1543 |
const lbl = document.getElementById('wf_seglabel_' + slot_id);
|
| 1544 |
if (lbl) lbl.textContent = 'Regenerating Seg ' + (idx + 1) + '...';
|
|
|
|
| 1531 |
function fireRegen(slot_id, idx) {
|
| 1532 |
const hidden_id = 'regen_trigger_' + slot_id;
|
| 1533 |
const el = document.getElementById(hidden_id);
|
| 1534 |
+
if (!el) { console.warn('[fireRegen] element not found:', hidden_id); return; }
|
| 1535 |
const input = el.querySelector('input, textarea');
|
| 1536 |
+
if (!input) { console.warn('[fireRegen] no input inside', hidden_id); return; }
|
| 1537 |
+
|
| 1538 |
+
// Gradio 5 / React: must use the native setter to bypass React's controlled-
|
| 1539 |
+
// input tracking, otherwise dispatchEvent is swallowed. Also must clear first
|
| 1540 |
+
// so a repeat regen of the same segment triggers a value *change*.
|
| 1541 |
+
const nativeInputDesc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')
|
| 1542 |
+
|| Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');
|
| 1543 |
+
function setAndFire(val) {
|
| 1544 |
+
if (nativeInputDesc && nativeInputDesc.set) {
|
| 1545 |
+
nativeInputDesc.set.call(input, val);
|
| 1546 |
+
} else {
|
| 1547 |
+
input.value = val;
|
| 1548 |
+
}
|
| 1549 |
+
input.dispatchEvent(new Event('input', {bubbles: true}));
|
| 1550 |
+
input.dispatchEvent(new Event('change', {bubbles: true}));
|
| 1551 |
+
}
|
| 1552 |
+
|
| 1553 |
+
// Clear first so even a repeated click on the same segment fires a change
|
| 1554 |
+
setAndFire('');
|
| 1555 |
+
setTimeout(function() {
|
| 1556 |
+
setAndFire(slot_id + '|' + idx);
|
| 1557 |
+
console.log('[fireRegen] fired', slot_id + '|' + idx);
|
| 1558 |
+
}, 50);
|
| 1559 |
+
|
| 1560 |
// Update status label
|
| 1561 |
const lbl = document.getElementById('wf_seglabel_' + slot_id);
|
| 1562 |
if (lbl) lbl.textContent = 'Regenerating Seg ' + (idx + 1) + '...';
|