Commit 0de34fe 1 parent b379c43 commit 0de34fe Copy full SHA for 0de34fe
File tree 1 file changed +22
-2
lines changed
electron/renderer/components/game
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,31 @@ export const GameContent: React.FC<GameContentProps> = (
34
34
return stream$ . pipe ( rxjs . filter ( ( m ) => gameStreamIds . includes ( m . streamId ) ) ) ;
35
35
} ) ;
36
36
37
+ const clearStreamTimeoutRef = useRef < NodeJS . Timeout | undefined > ( undefined ) ;
38
+
39
+ // Ensure the timeout is cleared when the component is unmounted.
40
+ useEffect ( ( ) => {
41
+ return ( ) => {
42
+ clearTimeout ( clearStreamTimeoutRef . current ) ;
43
+ } ;
44
+ } , [ ] ) ;
45
+
37
46
useSubscription ( filteredStream$ , ( logLine ) => {
38
47
if ( logLine . text === '__CLEAR_STREAM__' ) {
39
- setGameLogLines ( [ ] ) ;
48
+ // Clear the stream after a short delay to prevent flickering.
49
+ clearStreamTimeoutRef . current = setTimeout ( ( ) => {
50
+ setGameLogLines ( [ ] ) ;
51
+ } , 1000 ) ;
40
52
} else {
41
- appendGameLogLine ( logLine ) ;
53
+ // If we receieved a new log line, cancel any pending clear stream.
54
+ // Set the game log lines to the new log line to prevent flickering.
55
+ if ( clearStreamTimeoutRef . current ) {
56
+ clearTimeout ( clearStreamTimeoutRef . current ) ;
57
+ clearStreamTimeoutRef . current = undefined ;
58
+ setGameLogLines ( [ logLine ] ) ;
59
+ } else {
60
+ appendGameLogLine ( logLine ) ;
61
+ }
42
62
}
43
63
} ) ;
44
64
You can’t perform that action at this time.
0 commit comments