Fix Safari Upload
Description
- Issue: Media file upload and processing worked in Chrome but failed in Safari
- Root Causes: Safari's limited blob URL support and lack of OPFS (Origin Private File System) API
- Solution: Implemented Safari-specific fallbacks using FileReader + base64 data URLs and IndexedDB storage
References:
- https://stackoverflow.com/questions/68386273/error-loading-blob-to-img-in-safari-webkitblobresource-error-1
- https://github.com/diegomura/react-pdf/issues/536#issuecomment-1864980437
Fixes #189
Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
- [x] Upload MP4 in Safari
Test Configuration:
- Node version: v23.6.0
- Browser (if applicable): Safari
- Operating System: MacOS
Screenshots (if applicable)
Checklist:
- [ ] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
Additional context
Add any other context about the pull request here.
Summary by CodeRabbit
-
Bug Fixes
- Improved compatibility with Safari for storing and retrieving media files, ensuring reliable file handling across browsers.
- Enhanced media processing functions to support Safari, including image dimension extraction, video thumbnail generation, and media duration detection.
- Added more robust error handling and resource cleanup for media operations in Safari.
-
New Features
- Automatic browser detection to select the most compatible storage method for media files.
Deploy request for appcut pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | 363a901e8103b254ec28beca205c40523e428764 |
@maxdemaio is attempting to deploy a commit to the Maze Winther's projects Team on Vercel.
A member of the Team first needs to authorize it.
"""
Walkthrough
The changes introduce Safari-specific handling for file storage and media processing in the web application. The storage logic now detects Safari and uses IndexedDB instead of OPFS for media files. Media processing functions use base64 data URLs for Safari compatibility, improving file upload and handling reliability on Safari browsers.
Changes
| File(s) | Change Summary |
|---|---|
| apps/web/src/lib/storage/indexeddb-adapter.ts | Enhanced set and get methods to support storing and reconstructing File objects for Safari compatibility. |
| apps/web/src/lib/storage/storage-service.ts | Added Safari detection; conditionally uses IndexedDB for media storage on Safari, OPFS elsewhere. |
| apps/web/src/stores/media-store.ts | Modified media helper functions to use base64 data URLs and FileReader for Safari; improved error handling and resource cleanup. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant Browser
participant StorageService
participant IndexedDBAdapter
participant OPFSAdapter
User->>Browser: Uploads media file
Browser->>StorageService: Save media file
StorageService->>Browser: Detects browser (Safari or not)
alt Safari
StorageService->>IndexedDBAdapter: Store file (convert to ArrayBuffer)
IndexedDBAdapter-->>StorageService: File stored in IndexedDB
else Non-Safari (OPFS supported)
StorageService->>OPFSAdapter: Store file
OPFSAdapter-->>StorageService: File stored in OPFS
end
StorageService-->>Browser: Confirm upload
sequenceDiagram
participant User
participant Browser
participant MediaStore
User->>Browser: Uploads media file
Browser->>MediaStore: Process media (get dimensions, duration, thumbnail)
MediaStore->>Browser: Detects browser (Safari or not)
alt Safari
MediaStore->>Browser: Use FileReader to read as base64 data URL
Browser->>MediaStore: Provide media info
else Non-Safari
MediaStore->>Browser: Use Blob URL
Browser->>MediaStore: Provide media info
end
MediaStore-->>Browser: Return media info
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Fix Safari MP4 upload so that video uploads work as expected (#189) | ✅ | |
| Ensure no errors or hangs during Safari media file upload (#189) | ✅ | |
| Use compatible storage and media processing for Safari (#189) | ✅ |
Poem
In the warren of code where the browsers hop,
Safari once stumbled, its uploads would stop.
Now with base64 treats and careful device,
Files glide through IndexedDB—oh, isn’t that nice?
🐇✨
So let the carrots upload, let the videos play,
For every browser now hops the right way!
"""
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 6c29094476cca9657a8b47c8814ac2040aa076ae and 363a901e8103b254ec28beca205c40523e428764.
📒 Files selected for processing (1)
apps/web/src/stores/media-store.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/src/stores/media-store.ts
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
My code follows the style guidelines of this project
I ran bunx @biomejs/biome format --write [file] on the touched files, but then it looks like I've changed every line. I can add this commit if we'd like but I just rolled it back so it's easier to review the changes!
This doesn't resolve showing the thumbnail in the media section/timeline across refreshes, but the media is still there and can be dragged onto the timeline. I think that could be a separate issue.
fix merge conflicts and @ me please