Skip to content

Commit

Permalink
Use globalthis
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Nov 20, 2024
1 parent 2b71be4 commit 21a1cb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Bug Fixes

- `FormFileUpload`: Image Block: Fix transparent pngs not being uploaded correctly on Safari browser. ([67139](https://github.com/WordPress/gutenberg/pull/67139)).
- `FormFileUpload`: Prevent HEIC and HEIF files from being uploaded on Safari ([67139](https://github.com/WordPress/gutenberg/pull/67139)).

### Deprecations

Expand Down
13 changes: 6 additions & 7 deletions packages/components/src/form-file-upload/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useRef, useState, useEffect } from '@wordpress/element';
import { useRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -50,12 +50,11 @@ 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 [ isSafari, setIsSafari ] = useState( false );
useEffect( () => {
setIsSafari(
/^((?!chrome|android).)*safari/i.test( navigator.userAgent )
);
}, [] );
// Prevent Safari from adding "image/heic" and "image/heif" to the accept attribute.
const isSafari =
globalThis.navigator?.userAgent.includes( 'Safari' ) &&
! globalThis.navigator?.userAgent.includes( 'Chrome' ) &&
! globalThis.navigator?.userAgent.includes( 'Chromium' );
const compatAccept =
! isSafari && !! accept?.includes( 'image/*' )
? `${ accept }, image/heic, image/heif`
Expand Down

0 comments on commit 21a1cb0

Please sign in to comment.