From 88fc25fca168fcd19d078f7703a258d05932a461 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Wed, 21 Oct 2026 14:19:42 +0200 Subject: [PATCH] Fetch media library permission on demand instead of on mount (#11890) Co-authored-by: Claude Opus 5.5 --- src/lib/media/save-image.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/lib/media/save-image.ts b/src/lib/media/save-image.ts index b841bee75..0594aad0a 100644 --- a/src/lib/media/save-image.ts +++ b/src/lib/media/save-image.ts @@ -12,10 +12,15 @@ import {saveImageToMediaLibrary} from './manip' */ export function useSaveImageToMediaLibrary() { const {_} = useLingui() - const [permissionResponse, requestPermission, getPermission] = - MediaLibrary.usePermissions({ - granularPermissions: ['photo'], - }) + const [, requestPermission, getPermission] = MediaLibrary.usePermissions({ + granularPermissions: ['photo'], + /* + * Don't query the permission on mount. Every image embed in the feed + * mounts this hook, so the eager query cost a native call and a + * re-render per post. The save handler fetches it on demand instead. + */ + get: false, + }) return useCallback( async (uri: string) => { if (!IS_NATIVE) { @@ -34,7 +39,12 @@ export function useSaveImageToMediaLibrary() { } } - const permission = permissionResponse ?? (await getPermission()) + /* + * Always ask the OS instead of reusing the hook's cached response. The + * lightbox keeps this hook mounted for the whole session, so a cached + * denial would outlive the user granting access in system settings. + */ + const permission = await getPermission() if (permission.granted) { await save() @@ -63,6 +73,6 @@ export function useSaveImageToMediaLibrary() { } } }, - [permissionResponse, requestPermission, getPermission, _], + [requestPermission, getPermission, _], ) } -- knotmirror 0.0.1