fix: stabilize audio recording store subscription (#3524)

This commit is contained in:
Neil 2026-05-30 11:26:42 -07:00 committed by GitHub
parent 6ef7c4960e
commit ca53816aaa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 8 deletions

View File

@ -12,15 +12,21 @@ export const useMicrophonePermissions = createPermissionHook({
requestMethod: requestMicrophonePermissionsAsync
})
export function useIsRecording() {
const subscribe = (cb: () => void) => {
const sub = addExpoTwoWayAudioEventListener('onRecordingChange', cb)
return () => sub.remove()
}
const getSnapshot = () => isRecording()
const getServerSnapshot = () => false
// Why: useSyncExternalStore resubscribes when these identities change; keep
// the native recording listener stable across component re-renders.
const subscribeToRecordingChanges = (cb: () => void) => {
const sub = addExpoTwoWayAudioEventListener('onRecordingChange', cb)
return () => sub.remove()
}
const getRecordingSnapshot = () => isRecording()
const getServerRecordingSnapshot = () => false
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
export function useIsRecording() {
return useSyncExternalStore(
subscribeToRecordingChanges,
getRecordingSnapshot,
getServerRecordingSnapshot
)
}
export function useExpoTwoWayAudioEventListener<K extends keyof ExpoTwoWayAudioEventMap>(