Skip to content

πŸ› (rn-ble) [NO-ISSUE]: Fix BLE scan first emission delay#1308

Draft
OlivierFreyssinet wants to merge 1 commit intodevelopfrom
fix/no-issue-ble-scan-first-emission-delay
Draft

πŸ› (rn-ble) [NO-ISSUE]: Fix BLE scan first emission delay#1308
OlivierFreyssinet wants to merge 1 commit intodevelopfrom
fix/no-issue-ble-scan-first-emission-delay

Conversation

@OlivierFreyssinet
Copy link
Contributor

πŸ“ Description

Fixes a ~1 second delay before the first scanned BLE device appears in listenToAvailableDevices().

Root cause: In _startScanning(), the inner subject was a BehaviorSubject([]) which immediately emitted an empty []. This consumed the leading edge of throttleTime(1000), opening a 1s window that dropped the first real scan results. The first scanned device only appeared after the throttle window expired (~1s).

Fix: Replaced BehaviorSubject<InternalScannedDevice[]>([]) with ReplaySubject<InternalScannedDevice[]>(1) for the inner scan subject.

  • ReplaySubject(1) buffers the last value like BehaviorSubject (needed because the scan callback fires synchronously before switchMap subscribes to the returned observable) but has no initial emission, so the first real scan result passes through throttleTime immediately as the leading edge.
  • Connected devices continue to be fetched immediately (from the outer BehaviorSubject's initial emission) and polled every ~1s via the existing setInterval.

❓ Context

  • JIRA or GitHub link: NO-ISSUE

βœ… Checklist

  • Covered by automatic tests β€” 3 new tests added covering: (1) first scanned device appears immediately, (2) connected devices appear immediately with no scanned devices, (3) connected devices polling continues via interval
  • Changeset is provided
  • Documentation is up-to-date
  • Impact of the changes:
    • First scanned BLE device now appears immediately instead of being delayed by ~1s
    • Connected device polling behavior unchanged
    • No breaking changes to the public API

Made with Cursor

@vercel
Copy link

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
device-sdk-ts-sample Ready Ready Preview, Comment Feb 12, 2026 10:51am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
doc-device-management-kit Ignored Ignored Feb 12, 2026 10:51am

Request Review

@github-actions
Copy link
Contributor

Danger Check Results

Messages

βœ…

Danger: All checks passed successfully! πŸŽ‰

Generated by 🚫 dangerJS against 87f92db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant