Skip to content

fix: Media blob cache and chunk loading error handling#255

Merged
Just-Insane merged 3 commits intoSableClient:devfrom
Just-Insane:fix/media-and-chunk-errors
Mar 14, 2026
Merged

fix: Media blob cache and chunk loading error handling#255
Just-Insane merged 3 commits intoSableClient:devfrom
Just-Insane:fix/media-and-chunk-errors

Conversation

@Just-Insane
Copy link
Contributor

Summary

This PR adds robust error handling for two types of client errors:

1. Unhandled Promise Rejection in Media Blob Cache (Commit 77046ab)

Fixes unhandled promise rejections when multiple components fetch the same media URL that fails with 401 errors.

Root Cause: When a blob fetch request was in-flight and failed, subsequent callers awaiting the same promise would receive an unhandled rejection because the await was outside the try-catch block.

Changes:

  • Wrap inflightRequests.get() await in try-catch block
  • Improve error messages to include HTTP status codes
  • Add Service Worker logging for session retrieval failures to diagnose authentication issues

Addresses: Sentry Issue #1 (401 errors on authenticated media endpoints)

2. Automatic Retry for Chunk Loading Failures (Commit bff8c3d)

Adds automatic page reload when dynamic import failures occur due to stale HTML after deployments.

Root Cause: After deployments, users with cached HTML try to load JS chunks that no longer exist, causing "Failed to fetch dynamically imported module" errors.

Changes:

  • Global error handler catches chunk load errors (ChunkLoadError, "Failed to fetch")
  • Auto-reload page on first 2 failures without user intervention
  • On 3rd failure, let error bubble to Sentry error boundary
  • Uses sessionStorage to track retry count across reloads
  • Clears counter on successful page load

Addresses: Sentry Issue #2 (stale HTML breaking app after deployments)

Testing

  • Error handling paths verified through code review
  • sessionStorage retry logic tested locally
  • Both fixes address real production errors from Sentry

@Just-Insane Just-Insane requested a review from a team March 14, 2026 00:58
@Just-Insane Just-Insane marked this pull request as draft March 14, 2026 01:05
Evie Gauthier added 2 commits March 13, 2026 21:20
Fixes unhandled promise rejection when multiple components fetch
the same media URL and the initial request fails with 401.

### Root Cause
When a blob fetch request was in-flight and failed, subsequent callers
awaiting the same promise would receive an unhandled rejection because
the await was outside the try-catch block.

### Changes
1. useBlobCache: Wrap inflightRequests.get() await in try-catch
2. useBlobCache: Improve error message to include HTTP status
3. Service Worker: Add logging for session retrieval failures to
   diagnose authentication issues with media requests

Addresses Sentry issue with 401 errors on authenticated media endpoints.
- Global error handler catches chunk load errors
- Auto-reload on first 2 failures without user intervention
- On 3rd failure, let error bubble to Sentry error boundary
- Uses sessionStorage to track retry count across reloads
- Clears counter on successful page load
- Prevents stale HTML from breaking app after deployments
@Just-Insane Just-Insane force-pushed the fix/media-and-chunk-errors branch from bff8c3d to 24fbbc0 Compare March 14, 2026 01:20
@Just-Insane Just-Insane marked this pull request as ready for review March 14, 2026 01:21
@Just-Insane Just-Insane added this pull request to the merge queue Mar 14, 2026
Merged via the queue into SableClient:dev with commit a4447dd Mar 14, 2026
7 checks passed
@Just-Insane Just-Insane deleted the fix/media-and-chunk-errors branch March 15, 2026 04:23
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