Skip to content

Fix overlapping stream fetches by tracking request ids - #1353

Merged
K1NGD4VID merged 1 commit into
LabsCrypt:mainfrom
Peolite001:fix-stream-details-stale-data
Aug 30, 2026
Merged

Fix overlapping stream fetches by tracking request ids#1353
K1NGD4VID merged 1 commit into
LabsCrypt:mainfrom
Peolite001:fix-stream-details-stale-data

Conversation

@Peolite001

@Peolite001 Peolite001 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an issue where overlapping fetch requests for stream details and events (caused by rapid SSE bursts) could resolve out of order and apply stale data. Previously, the refresh effect created a new AbortController on each update, but this didn't prevent an already in-flight, slower fetch from resolving late and overwriting newer state data within the same mount.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update

Related Issues

Closes #1212

Changes Made

  • Implemented monotonic request ID tracking using useRef for both fetchStream and fetchEvents in frontend/src/app/streams/[id]/stream-details-content.tsx.
  • Updated state setters within the fetchStream and fetchEvents callbacks to check that the current request ID matches the latest request ID before applying the fetched data to state, safely discarding outdated overlapping responses.

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

  1. Navigate to a stream details page.
  2. Trigger two rapid, sequential SSE events to the stream in quick succession.
  3. Simulate or observe a scenario where the first request's latency exceeds the second request's latency.
  4. Verify that the UI ultimately renders the data from the final, most recent event without rolling back to stale data from the delayed first fetch.

Breaking Changes

Breaking Changes:

  • None

Migration Guide:

  • N/A

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Updated Postman/Hoppscotch API collections if routes changed
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked for breaking changes and documented them if applicable

Additional Notes

By explicitly tracking request IDs manually on the callbacks instead of heavily restructuring the useEffect scope for aborts, this prevents overlapping state updates directly regardless of where the fetch callbacks are invoked from (e.g. initial loads, manual top-ups, SSE events).

@K1NGD4VID
K1NGD4VID merged commit 68abd26 into LabsCrypt:main Aug 30, 2026
10 checks passed
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.

[Audit] Overlapping stream-detail fetches on rapid SSE bursts can apply stale data

2 participants