fix: prevent config overwrite, session history race, and streaming message loss (#663)
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
8c3a6a5f7a
commit
83858fdf73
@@ -45,7 +45,16 @@ export function subscribeHostEvent<T = unknown>(
|
||||
const listener = (payload: unknown) => {
|
||||
handler(payload as T);
|
||||
};
|
||||
ipc.on(ipcChannel, listener);
|
||||
// preload's `on()` wraps the callback in an internal subscription function
|
||||
// and returns a cleanup function that removes that exact wrapper. We MUST
|
||||
// use the returned cleanup rather than calling `off(channel, listener)`,
|
||||
// because `listener` !== the internal wrapper and removeListener would be
|
||||
// a no-op, leaking the subscription.
|
||||
const unsubscribe = ipc.on(ipcChannel, listener);
|
||||
if (typeof unsubscribe === 'function') {
|
||||
return unsubscribe;
|
||||
}
|
||||
// Fallback for environments where on() doesn't return cleanup
|
||||
return () => {
|
||||
ipc.off(ipcChannel, listener);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user