Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormFileUpload: Prevent HEIC and HEIF files from always being uploaded on Safari #67139

Merged
merged 8 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixes

- `FormFileUpload`: Prevent HEIC and HEIF files from being uploaded on Safari ([#67139](https://github.com/WordPress/gutenberg/pull/67139)).

### Deprecations

- `Radio`: Deprecate 36px default size ([#66572](https://github.com/WordPress/gutenberg/pull/66572)).
Expand Down
12 changes: 9 additions & 3 deletions packages/components/src/form-file-upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ export function FormFileUpload( {
// @todo: Temporary fix a bug that prevents Chromium browsers from selecting ".heic" files
// from the file upload. See https://core.trac.wordpress.org/ticket/62268#comment:4.
// This can be removed once the Chromium fix is in the stable channel.
const compatAccept = !! accept?.includes( 'image/*' )
? `${ accept }, image/heic, image/heif`
: accept;
// Prevent Safari from adding "image/heic" and "image/heif" to the accept attribute.
const isSafari =
globalThis.window?.navigator.userAgent.includes( 'Safari' ) &&
! globalThis.window?.navigator.userAgent.includes( 'Chrome' ) &&
! globalThis.window?.navigator.userAgent.includes( 'Chromium' );
const compatAccept =
! isSafari && !! accept?.includes( 'image/*' )
? `${ accept }, image/heic, image/heif`
: accept;

return (
<div className="components-form-file-upload">
Expand Down
Loading