Fix stale closure on existing keys

This commit is contained in:
Jack Kingsman
2026-03-02 16:38:44 -08:00
parent 69584051f5
commit e3fe36dc19

View File

@@ -98,6 +98,7 @@ export function CrackerPanel({
const twoWordModeRef = useRef(false);
const undecryptedIdsRef = useRef<Set<number>>(new Set());
const seenPayloadsRef = useRef<Set<string>>(new Set());
const existingChannelKeysRef = useRef<Set<string>>(new Set());
// Initialize cracker and NoSleep
useEffect(() => {
@@ -155,6 +156,10 @@ export function CrackerPanel({
[channels]
);
useEffect(() => {
existingChannelKeysRef.current = existingChannelKeys;
}, [existingChannelKeys]);
// Filter packets to only undecrypted GROUP_TEXT
const undecryptedGroupText = packets.filter(
(p) => p.payload_type === 'GROUP_TEXT' && !p.decrypted
@@ -365,7 +370,7 @@ export function CrackerPanel({
// Auto-add channel if not already exists
const keyUpper = result.key.toUpperCase();
if (!existingChannelKeys.has(keyUpper)) {
if (!existingChannelKeysRef.current.has(keyUpper)) {
try {
const channelName = '#' + result.roomName;
await onChannelCreate(channelName, result.key);
@@ -426,7 +431,7 @@ export function CrackerPanel({
if (isRunningRef.current) {
setTimeout(() => processNext(), 100);
}
}, [existingChannelKeys, onChannelCreate]);
}, [onChannelCreate]);
// Start/stop handlers
const handleStart = () => {