Skip to content

Commit b659d08

Browse files
committed
fix: capture scroll anchor before delayed callback
The generate-complete scroll used a bare setTimeout that dereferenced document after up to 100ms. Under slower CI workers the callback fired after the test environment tore down, surfacing as an unhandled ReferenceError: document is not defined and failing the run even with every test and coverage gate passing. Capturing the element synchronously removes the teardown race without changing app behavior.
1 parent 35ce7e2 commit b659d08

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/pages/GeneratePage.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ export default function GeneratePage() {
6060
setDiscoveredSources(sources);
6161
setGenerateResult(result);
6262
toast({ title: t('generate.complete', 'Generate complete'), description: t('generate.completeDesc', 'Your debate case is ready.'), variant: 'success' });
63-
setTimeout(() => document.getElementById('generate-results')?.scrollIntoView({ behavior: 'smooth', block: 'start' }), 100);
63+
// Capture the node now; the delayed callback must not touch the global
64+
// document after this async flow may have been torn down (test and
65+
// unmount safety).
66+
const resultsAnchor = document.getElementById('generate-results');
67+
setTimeout(() => resultsAnchor?.scrollIntoView({ behavior: 'smooth', block: 'start' }), 100);
6468
} catch (error) {
6569
console.error('Failed to generate case:', error);
6670

0 commit comments

Comments
 (0)