Skip to content

Conversation

@mikestankavich
Copy link
Contributor

Summary

  • Fixes race condition where trigger release was processed before barcode store subscription could fire
  • Adds 150ms delay before resetting isScanningRef on trigger release
  • Allows barcode data to be captured on Windows Chrome (affected more than macOS due to JS event loop timing differences)

Root Cause

When scanning barcodes in Asset/Location forms via hardware trigger:

  1. Trigger pressed → isScanningRef.current = true
  2. CS108 scans barcode → data goes to useBarcodeStore
  3. Trigger released → isScanningRef.current = falsehappened too fast
  4. Store subscription fires → checks isScanningRef.currentfalse, discards barcode!

Test plan

  • Test barcode scanning in Asset form on Windows Chrome
  • Test barcode scanning in Location form on Windows Chrome
  • Verify macOS behavior unchanged
  • Verify trigger press/release timing works correctly

🤖 Generated with Claude Code

Fixes a race condition where the trigger release event was processed
before the barcode store subscription could fire, causing scanned
barcode data to be discarded. This affected Windows Chrome more than
macOS due to different JavaScript event loop timing.

The fix adds a 150ms delay before resetting isScanningRef on trigger
release, giving the barcode store subscription time to process any
pending barcode data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 13, 2026
Replace timing-based race condition fix with deterministic approach:
- Track barcode count when scan starts (startCount)
- Subscription compares barcodes.length > startCount
- Session stays active 2s after trigger release to catch late data
- New trigger during cooldown cancels old session and starts fresh

This eliminates timing dependency entirely - comparison is deterministic.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
Mike Stankavich and others added 2 commits January 13, 2026 18:57
Don't call dm.setMode() immediately on trigger release - this was
aborting the CS108 scan mid-transmission causing truncated reads.

Now mode switch happens:
- Immediately after barcode data received (via endScanSession)
- OR after 2s timeout if no data (fallback cleanup)

This gives the CS108 time to finish transmitting barcode data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Give CS108 500ms to finish transmitting data after trigger release
- Switch modes after 500ms, keep session open 1.5s more for late data
- End immediately on clean read (endScanSession cancels timeouts)

Total timing: 500ms grace + 1.5s late data window = 2s max
Clean read: immediate mode switch, no waiting

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
Add onMouseDown with preventDefault to stop the tag input from losing
focus when clicking the Scan button. This prevents the button from
being disabled before the click event fires.

Applied to both AssetForm and LocationForm.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
Don't switch modes until data arrives or 2s timeout - more forgiving
for slow machines. Mode switch only happens via:
- endScanSession() when data arrives (immediate)
- 2s timeout cleanup (fallback)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
Remove stripAimIdentifier - was causing empty data on some machines.
Now passes raw barcode.data directly, same as BarcodeScreen displays.

Also switched from subscription to reactive state for barcode detection
which is more reliable on slow machines.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
Re-add stripAimIdentifier to extract data after QR prefix (Q]Q1...).
Added console.debug logging to help diagnose issues on Tim's machine.

Example: "Q]Q1000000000000000000000130" -> "000000000000000000000130"

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
@mikestankavich mikestankavich force-pushed the fix/scan-to-input-race-condition branch from 93b789d to 2d1cefa Compare January 14, 2026 01:45
@github-actions
Copy link

🚀 Preview Deployment Update

✅ This PR has been successfully merged into the preview branch.

The preview environment will update shortly at: https://app.preview.trakrf.id

github-actions bot added a commit that referenced this pull request Jan 14, 2026
github-actions bot added a commit that referenced this pull request Jan 14, 2026
@mikestankavich mikestankavich merged commit a1b9c26 into main Jan 14, 2026
6 checks passed
@mikestankavich mikestankavich deleted the fix/scan-to-input-race-condition branch January 14, 2026 01:57
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.

2 participants