From 16509141338cb70f48c5ad2ee66a4a73c2ce5e16 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Thu, 16 Jul 2026 10:10:11 -0700 Subject: [PATCH 1/2] Fix upload snackbar double-counting a single HEIC upload in Safari In HEIC-only canvas mode (Safari, where full client-side media processing is unsupported), the upload-media queue counts the HEIC item for the progress snackbar and then calls the editor's mediaUpload wrapper as its server transport. The wrapper's environment check could not tell that call apart from a direct block upload, so it registered the same file with the snackbar tracker again, showing 'Uploading 1 of 2' for a single file. Pass an explicit skipTracking flag from the queue's uploadItem so the wrapper skips tracker registration for queue transport calls, while direct non-CSM uploads keep being tracked. --- packages/editor/CHANGELOG.md | 4 + packages/editor/README.md | 1 + .../editor/src/utils/media-upload/index.js | 23 +++-- .../editor/src/utils/test/media-upload.js | 75 ++++++++++++++ packages/upload-media/CHANGELOG.md | 10 +- .../upload-media/src/store/private-actions.ts | 4 + .../src/store/test/private-actions.js | 33 +++++++ packages/upload-media/src/store/types.ts | 3 + .../heic-upload-progress-snackbar.spec.js | 98 +++++++++++++++++++ 9 files changed, 242 insertions(+), 9 deletions(-) create mode 100644 packages/editor/src/utils/test/media-upload.js create mode 100644 test/e2e/specs/editor/various/heic-upload-progress-snackbar.spec.js diff --git a/packages/editor/CHANGELOG.md b/packages/editor/CHANGELOG.md index a7123f419694e3..35417a1f92bb2a 100644 --- a/packages/editor/CHANGELOG.md +++ b/packages/editor/CHANGELOG.md @@ -6,6 +6,10 @@ - The "Apply globally" control now opens a review modal so you can choose which of a block's modified styles are pushed to Global Styles, showing each style's current and new value ([#79839](https://github.com/WordPress/gutenberg/pull/79839)). +### Bug Fixes + +- `mediaUpload`: Skip upload progress tracking when called by the `@wordpress/upload-media` queue, which counts its own items. Fixes the progress snackbar showing "1 of 2" for a single HEIC upload in Safari ([#80369](https://github.com/WordPress/gutenberg/issues/80369)). + ## 14.51.0 (2026-07-14) ### New Features diff --git a/packages/editor/README.md b/packages/editor/README.md index 724d8ed94fc242..c1b671f134820a 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -488,6 +488,7 @@ _Parameters_ - _$0.onFileChange_ `Function`: Function called each time a file or a temporary representation of the file is available. - _$0.onSuccess_ `Function`: Function called after the final representation of the file is available. - _$0.multiple_ `boolean`: Whether to allow multiple files to be uploaded. +- _$0.skipTracking_ `boolean`: Whether the caller tracks upload progress itself. Set by the `@wordpress/upload-media` queue, which counts its own items for the progress snackbar and uses this function only as its server transport. ### MediaUploadCheck diff --git a/packages/editor/src/utils/media-upload/index.js b/packages/editor/src/utils/media-upload/index.js index 740060dd672ec4..793bc02f3b92f0 100644 --- a/packages/editor/src/utils/media-upload/index.js +++ b/packages/editor/src/utils/media-upload/index.js @@ -35,6 +35,9 @@ const noop = () => {}; * @param {Function} $0.onFileChange Function called each time a file or a temporary representation of the file is available. * @param {Function} $0.onSuccess Function called after the final representation of the file is available. * @param {boolean} $0.multiple Whether to allow multiple files to be uploaded. + * @param {boolean} $0.skipTracking Whether the caller tracks upload progress itself. Set by the + * `@wordpress/upload-media` queue, which counts its own items for the + * progress snackbar and uses this function only as its server transport. */ export default function mediaUpload( { additionalData = {}, @@ -45,6 +48,7 @@ export default function mediaUpload( { onFileChange, onSuccess, multiple = true, + skipTracking = false, } ) { const { receiveEntityRecords } = dispatch( coreDataStore ); const { getCurrentPost, getEditorSettings } = select( editorStore ); @@ -82,11 +86,16 @@ export default function mediaUpload( { const postData = currentPostId ? { post: currentPostId } : {}; - // Track this batch for the upload progress snackbar. Only applies to the - // non-CSM path — when CSM is enabled, the block-editor provider intercepts - // mediaUpload and dispatches to the upload-media store, so this wrapper is - // not called. - if ( ! isClientSideMediaActive ) { + // Track this batch for the upload progress snackbar. Only applies to + // direct calls on the non-CSM path — when CSM is enabled, the + // block-editor provider intercepts mediaUpload and dispatches to the + // upload-media store instead. The upload-media queue also calls this + // wrapper as its server transport (with `skipTracking` set) even when + // full CSM is unsupported — e.g. Safari's HEIC-only canvas mode — and + // its items are already counted by the snackbar, so registering them + // here would double-count them (see gutenberg#80369). + const shouldTrack = ! isClientSideMediaActive && ! skipTracking; + if ( shouldTrack ) { const trackingFiles = Array.from( filesList ).map( ( f ) => f?.name || '' ); @@ -124,7 +133,7 @@ export default function mediaUpload( { } // Advance the snackbar tracker for newly-completed files. - if ( ! isClientSideMediaActive ) { + if ( shouldTrack ) { const completedCount = entityFiles.length; if ( completedCount > lastCompletedCount ) { trackAdvance( completedCount - lastCompletedCount ); @@ -141,6 +150,8 @@ export default function mediaUpload( { onError: ( { message } ) => { if ( ! isClientSideMediaActive ) { clearSaveLock(); + } + if ( shouldTrack ) { // Failed files still count as "done" for the snackbar. trackAdvance( 1 ); } diff --git a/packages/editor/src/utils/test/media-upload.js b/packages/editor/src/utils/test/media-upload.js new file mode 100644 index 00000000000000..7dac8a422c3530 --- /dev/null +++ b/packages/editor/src/utils/test/media-upload.js @@ -0,0 +1,75 @@ +/** + * Internal dependencies + */ +import mediaUpload from '../media-upload'; +import { + getState, + reset, +} from '../../components/upload-progress-snackbar/tracker'; + +jest.mock( '@wordpress/media-utils', () => ( { + uploadMedia: jest.fn(), +} ) ); + +jest.mock( '@wordpress/upload-media', () => ( { + isClientSideMediaSupported: jest.fn( () => false ), +} ) ); + +jest.mock( '@wordpress/core-data', () => ( { + store: { name: 'core' }, +} ) ); + +jest.mock( '../../store', () => ( { + store: { name: 'core/editor' }, +} ) ); + +jest.mock( '@wordpress/data', () => ( { + select: jest.fn( () => ( { + getCurrentPost: () => ( { id: 1 } ), + getEditorSettings: () => ( { + allowedMimeTypes: null, + maxUploadFileSize: 10 * 1024 * 1024, + } ), + } ) ), + dispatch: jest.fn( () => ( { + receiveEntityRecords: jest.fn(), + lockPostSaving: jest.fn(), + unlockPostSaving: jest.fn(), + lockPostAutosaving: jest.fn(), + unlockPostAutosaving: jest.fn(), + } ) ), +} ) ); + +describe( 'mediaUpload', () => { + beforeEach( () => { + reset(); + } ); + + it( 'registers files with the upload progress tracker', () => { + const file = new File( [ 'content' ], 'photo.jpg', { + type: 'image/jpeg', + } ); + + mediaUpload( { filesList: [ file ] } ); + + expect( getState() ).toEqual( { + total: 1, + completed: 0, + pending: [ 'photo.jpg' ], + } ); + } ); + + it( 'skips tracker registration when the caller tracks progress itself', () => { + // The upload-media queue calls this wrapper as its server transport + // and already counts its own queue items for the progress snackbar; + // registering the same file here would double-count it + // (see gutenberg#80369). + const file = new File( [ 'content' ], 'photo.jpg', { + type: 'image/jpeg', + } ); + + mediaUpload( { filesList: [ file ], skipTracking: true } ); + + expect( getState() ).toBeNull(); + } ); +} ); diff --git a/packages/upload-media/CHANGELOG.md b/packages/upload-media/CHANGELOG.md index efedf1fffa2bc3..670e4c94314912 100644 --- a/packages/upload-media/CHANGELOG.md +++ b/packages/upload-media/CHANGELOG.md @@ -4,17 +4,21 @@ ### Breaking Changes -- `vipsResizeImage`, `vipsCompressImage`, and `vipsConvertImageFormat` now accept their optional parameters (`smartCrop`, `addSuffix`, `signal`, `scaledSuffix`, `quality`, `interlaced`, `stripMeta`, `maxBitdepth`) as a single trailing `options` object instead of positional arguments ([#80328](https://github.com/WordPress/gutenberg/issues/80328)). +- `vipsResizeImage`, `vipsCompressImage`, and `vipsConvertImageFormat` now accept their optional parameters (`smartCrop`, `addSuffix`, `signal`, `scaledSuffix`, `quality`, `interlaced`, `stripMeta`, `maxBitdepth`) as a single trailing `options` object instead of positional arguments ([#80328](https://github.com/WordPress/gutenberg/issues/80328)). ### Enhancements -- Honor the `image_strip_meta` and `image_max_bit_depth` filters for client-side processed images via the new `imageStripMeta` and `imageMaxBitDepth` settings, carried in the REST API root index ([#80216](https://github.com/WordPress/gutenberg/issues/80216)). +- Honor the `image_strip_meta` and `image_max_bit_depth` filters for client-side processed images via the new `imageStripMeta` and `imageMaxBitDepth` settings, carried in the REST API root index ([#80216](https://github.com/WordPress/gutenberg/issues/80216)). + +### Bug Fixes + +- Pass `skipTracking: true` to the `mediaUpload` setting when the queue uploads a file, so consumers that track upload progress themselves don't count the same file twice ([#80369](https://github.com/WordPress/gutenberg/issues/80369)). ## 0.36.0 (2026-07-14) ### Enhancement -- Honor the `wp_editor_set_quality` filter for client-side processed images. Sub-size resizing and transcoding now use the size-aware quality reported by the new `image_quality` field on the attachment upload response, instead of a hardcoded default. +- Honor the `wp_editor_set_quality` filter for client-side processed images. Sub-size resizing and transcoding now use the size-aware quality reported by the new `image_quality` field on the attachment upload response, instead of a hardcoded default. ### Enhancements diff --git a/packages/upload-media/src/store/private-actions.ts b/packages/upload-media/src/store/private-actions.ts index 93a4ebd3737819..c91cb12bfd77de 100644 --- a/packages/upload-media/src/store/private-actions.ts +++ b/packages/upload-media/src/store/private-actions.ts @@ -1034,6 +1034,10 @@ export function uploadItem( id: QueueItemId ) { filesList: [ item.file ], additionalData: item.additionalData, signal: item.abortController?.signal, + // The queue's own items drive upload progress UI; without this, + // consumers that track uploads themselves (e.g. the editor's + // progress snackbar) would count this file a second time. + skipTracking: true, onFileChange: ( [ attachment ] ) => { if ( attachment && ! isBlobURL( attachment.url ) ) { finishUpload( attachment ); diff --git a/packages/upload-media/src/store/test/private-actions.js b/packages/upload-media/src/store/test/private-actions.js index ba5cc43741bf64..c098529a945edd 100644 --- a/packages/upload-media/src/store/test/private-actions.js +++ b/packages/upload-media/src/store/test/private-actions.js @@ -20,6 +20,7 @@ import { transcodeGifItem, detectUltraHdr, removeItem, + uploadItem, } from '../private-actions'; import { OperationType, Type } from '../types'; import { @@ -1413,6 +1414,38 @@ describe( 'private actions', () => { } ); } ); + describe( 'uploadItem', () => { + it( 'flags the transport call so consumers skip their own progress tracking', async () => { + // The queue already counts its items for progress UI; the + // `mediaUpload` callback it delegates the server upload to must + // not count the same file again (see gutenberg#80369). + const mediaUpload = jest.fn(); + const file = new File( [ 'content' ], 'photo.jpg', { + type: 'image/jpeg', + } ); + const item = { id: 'item-1', file, additionalData: {} }; + + const dispatch = jest.fn(); + dispatch.finishOperation = jest.fn(); + dispatch.cancelItem = jest.fn(); + + await uploadItem( 'item-1' )( { + select: { + getItem: () => item, + getSettings: () => ( { mediaUpload } ), + }, + dispatch, + } ); + + expect( mediaUpload ).toHaveBeenCalledWith( + expect.objectContaining( { + filesList: [ file ], + skipTracking: true, + } ) + ); + } ); + } ); + describe( 'removeItem worker teardown', () => { beforeEach( () => { jest.clearAllMocks(); diff --git a/packages/upload-media/src/store/types.ts b/packages/upload-media/src/store/types.ts index 209a7dd8b474a5..92ba76fa07a3e8 100644 --- a/packages/upload-media/src/store/types.ts +++ b/packages/upload-media/src/store/types.ts @@ -174,6 +174,9 @@ interface UploadMediaArgs { wpAllowedMimeTypes?: Record< string, string > | null; // Abort signal. signal?: AbortSignal; + // Whether the caller tracks upload progress itself, so the handler + // should skip its own progress tracking to avoid double-counting. + skipTracking?: boolean; } /** diff --git a/test/e2e/specs/editor/various/heic-upload-progress-snackbar.spec.js b/test/e2e/specs/editor/various/heic-upload-progress-snackbar.spec.js new file mode 100644 index 00000000000000..abd0e26ff49365 --- /dev/null +++ b/test/e2e/specs/editor/various/heic-upload-progress-snackbar.spec.js @@ -0,0 +1,98 @@ +/** + * External dependencies + */ +const path = require( 'path' ); +const fs = require( 'fs' ); + +/** + * WordPress dependencies + */ +const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); + +test.describe( 'Upload progress snackbar (HEIC-only canvas mode) (@webkit)', () => { + test.beforeAll( async ( { requestUtils } ) => { + // Disable full client-side media processing while leaving the + // HEIC canvas-conversion mode active (`window.__heicUploadSupport` + // is set regardless). This mirrors Safari, where full client-side + // processing is unsupported but HEIC files are still converted to + // JPEG via createImageBitmap + OffscreenCanvas before upload. + await requestUtils.activatePlugin( + 'gutenberg-test-plugin-disable-client-side-media-processing' + ); + } ); + + test.beforeEach( async ( { admin } ) => { + await admin.createNewPost(); + } ); + + test.afterEach( async ( { requestUtils } ) => { + await requestUtils.deleteAllMedia(); + } ); + + test.afterAll( async ( { requestUtils } ) => { + await requestUtils.deactivatePlugin( + 'gutenberg-test-plugin-disable-client-side-media-processing' + ); + } ); + + test( 'counts a single HEIC upload as one file', async ( { + editor, + page, + } ) => { + await editor.insertBlock( { name: 'core/image' } ); + + // A JPEG payload with an `image/heic` MIME type: the HEIC-only mode + // routes files by type, and `createImageBitmap()` decodes by content, + // so this exercises the exact HEIC conversion pipeline in Chromium, + // which cannot decode real HEIC data. + const buffer = fs.readFileSync( + path.join( + __dirname, + '..', + '..', + '..', + 'assets', + '1024x768_e2e_test_image_size.jpeg' + ) + ); + + const imageBlock = editor.canvas.locator( + 'role=document[name="Block: Image"i]' + ); + await imageBlock + .locator( 'data-testid=form-file-upload-input' ) + .setInputFiles( { + name: 'IMG_1982.heic', + mimeType: 'image/heic', + buffer, + } ); + + const snackbarList = page.locator( '.components-snackbar-list' ); + + // A single file must use the single-file message throughout. The + // double-counted state ("Uploading 1 of 2 — …") appears mid-upload, + // so race it against the completion snackbar: completion has to win + // (regression: gutenberg#80369). + const multiFileText = snackbarList.getByText( /Uploading \d+ of \d+/ ); + const completeText = snackbarList.getByText( 'Upload complete' ); + const outcome = await Promise.race( [ + multiFileText + .waitFor( { state: 'visible', timeout: 60_000 } ) + .then( () => 'multi-file count shown' ) + .catch( () => 'multi-file text never appeared' ), + completeText + .waitFor( { state: 'visible', timeout: 60_000 } ) + .then( () => 'upload complete' ) + .catch( () => 'completion snackbar never appeared' ), + ] ); + expect( outcome ).toBe( 'upload complete' ); + + // The HEIC file was converted client-side and uploaded as a JPEG. + const image = imageBlock.getByRole( 'img', { + name: 'This image has an empty alt attribute', + } ); + await expect( image ).toHaveAttribute( 'src', /IMG_1982.*\.jpg/, { + timeout: 30_000, + } ); + } ); +} ); From e5698cca8dd8fc3845fb6bff17061775c8ea4ba0 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Thu, 16 Jul 2026 23:33:43 -0700 Subject: [PATCH 2/2] Rename skipTracking to isTransportOnly and drop CSM sniffing in mediaUpload Per review feedback, the wrapper now keys all lifecycle behavior (progress tracking and save locking) off explicit caller intent instead of detecting whether client-side media processing is active. Transport calls from the upload-media queue skip both, since the queue counts its own items for the snackbar and locks saving via useUploadSaveLock; direct calls always track and lock, closing a gap where a direct upload under CSM got neither. --- packages/editor/CHANGELOG.md | 2 +- packages/editor/README.md | 2 +- .../editor/src/utils/media-upload/index.js | 46 +++++++------------ .../editor/src/utils/test/media-upload.js | 30 ++++++------ packages/upload-media/CHANGELOG.md | 2 +- .../upload-media/src/store/private-actions.ts | 9 ++-- .../src/store/test/private-actions.js | 4 +- packages/upload-media/src/store/types.ts | 6 +-- 8 files changed, 47 insertions(+), 54 deletions(-) diff --git a/packages/editor/CHANGELOG.md b/packages/editor/CHANGELOG.md index 35417a1f92bb2a..aaeed12c50c67c 100644 --- a/packages/editor/CHANGELOG.md +++ b/packages/editor/CHANGELOG.md @@ -8,7 +8,7 @@ ### Bug Fixes -- `mediaUpload`: Skip upload progress tracking when called by the `@wordpress/upload-media` queue, which counts its own items. Fixes the progress snackbar showing "1 of 2" for a single HEIC upload in Safari ([#80369](https://github.com/WordPress/gutenberg/issues/80369)). +- `mediaUpload`: Add an `isTransportOnly` parameter, set by the `@wordpress/upload-media` queue, which owns progress tracking and save locking for its own items and uses this function only as its server transport. Fixes the progress snackbar showing "1 of 2" for a single HEIC upload in Safari ([#80369](https://github.com/WordPress/gutenberg/issues/80369)). ## 14.51.0 (2026-07-14) diff --git a/packages/editor/README.md b/packages/editor/README.md index c1b671f134820a..f2df131df56d30 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -488,7 +488,7 @@ _Parameters_ - _$0.onFileChange_ `Function`: Function called each time a file or a temporary representation of the file is available. - _$0.onSuccess_ `Function`: Function called after the final representation of the file is available. - _$0.multiple_ `boolean`: Whether to allow multiple files to be uploaded. -- _$0.skipTracking_ `boolean`: Whether the caller tracks upload progress itself. Set by the `@wordpress/upload-media` queue, which counts its own items for the progress snackbar and uses this function only as its server transport. +- _$0.isTransportOnly_ `boolean`: Whether the caller owns the upload lifecycle UX (progress tracking and save locking) and uses this function only as its server transport. Set by the `@wordpress/upload-media` queue, which counts its own items for the progress snackbar and locks saving via `useUploadSaveLock`. ### MediaUploadCheck diff --git a/packages/editor/src/utils/media-upload/index.js b/packages/editor/src/utils/media-upload/index.js index 793bc02f3b92f0..1ab0a69be0d2f7 100644 --- a/packages/editor/src/utils/media-upload/index.js +++ b/packages/editor/src/utils/media-upload/index.js @@ -9,7 +9,6 @@ import { v4 as uuid } from 'uuid'; import { select, dispatch } from '@wordpress/data'; import { store as coreDataStore } from '@wordpress/core-data'; import { uploadMedia } from '@wordpress/media-utils'; -import { isClientSideMediaSupported } from '@wordpress/upload-media'; /** * Internal dependencies @@ -35,9 +34,10 @@ const noop = () => {}; * @param {Function} $0.onFileChange Function called each time a file or a temporary representation of the file is available. * @param {Function} $0.onSuccess Function called after the final representation of the file is available. * @param {boolean} $0.multiple Whether to allow multiple files to be uploaded. - * @param {boolean} $0.skipTracking Whether the caller tracks upload progress itself. Set by the - * `@wordpress/upload-media` queue, which counts its own items for the - * progress snackbar and uses this function only as its server transport. + * @param {boolean} $0.isTransportOnly Whether the caller owns the upload lifecycle UX (progress tracking and + * save locking) and uses this function only as its server transport. Set + * by the `@wordpress/upload-media` queue, which counts its own items for + * the progress snackbar and locks saving via `useUploadSaveLock`. */ export default function mediaUpload( { additionalData = {}, @@ -48,7 +48,7 @@ export default function mediaUpload( { onFileChange, onSuccess, multiple = true, - skipTracking = false, + isTransportOnly = false, } ) { const { receiveEntityRecords } = dispatch( coreDataStore ); const { getCurrentPost, getEditorSettings } = select( editorStore ); @@ -60,8 +60,6 @@ export default function mediaUpload( { } = dispatch( editorStore ); const wpAllowedMimeTypes = getEditorSettings().allowedMimeTypes; - const isClientSideMediaActive = - window.__clientSideMediaProcessing && isClientSideMediaSupported(); const lockKey = `image-upload-${ uuid() }`; maxUploadFileSize = maxUploadFileSize || getEditorSettings().maxUploadFileSize; @@ -76,26 +74,21 @@ export default function mediaUpload( { unlockPostAutosaving( lockKey ); }; - // Lock saving immediately when the upload starts. - // When client-side media processing is enabled, save locking - // is handled by useUploadSaveLock in the editor provider. - if ( ! isClientSideMediaActive ) { + // Lock saving immediately when the upload starts. Skipped for transport + // calls from the `@wordpress/upload-media` queue, whose items already + // lock saving via useUploadSaveLock in the editor provider. + if ( ! isTransportOnly ) { lockPostSaving( lockKey ); lockPostAutosaving( lockKey ); } const postData = currentPostId ? { post: currentPostId } : {}; - // Track this batch for the upload progress snackbar. Only applies to - // direct calls on the non-CSM path — when CSM is enabled, the - // block-editor provider intercepts mediaUpload and dispatches to the - // upload-media store instead. The upload-media queue also calls this - // wrapper as its server transport (with `skipTracking` set) even when - // full CSM is unsupported — e.g. Safari's HEIC-only canvas mode — and - // its items are already counted by the snackbar, so registering them - // here would double-count them (see gutenberg#80369). - const shouldTrack = ! isClientSideMediaActive && ! skipTracking; - if ( shouldTrack ) { + // Track this batch for the upload progress snackbar. Skipped for + // transport calls from the `@wordpress/upload-media` queue — its items + // are already counted by the snackbar, so registering them here would + // double-count them (see gutenberg#80369). + if ( ! isTransportOnly ) { const trackingFiles = Array.from( filesList ).map( ( f ) => f?.name || '' ); @@ -125,15 +118,12 @@ export default function mediaUpload( { } // Unlock saving once all files have been uploaded (all have IDs). - if ( - ! isClientSideMediaActive && - entityFiles.length === files.length - ) { + if ( ! isTransportOnly && entityFiles.length === files.length ) { clearSaveLock(); } // Advance the snackbar tracker for newly-completed files. - if ( shouldTrack ) { + if ( ! isTransportOnly ) { const completedCount = entityFiles.length; if ( completedCount > lastCompletedCount ) { trackAdvance( completedCount - lastCompletedCount ); @@ -148,10 +138,8 @@ export default function mediaUpload( { }, maxUploadFileSize, onError: ( { message } ) => { - if ( ! isClientSideMediaActive ) { + if ( ! isTransportOnly ) { clearSaveLock(); - } - if ( shouldTrack ) { // Failed files still count as "done" for the snackbar. trackAdvance( 1 ); } diff --git a/packages/editor/src/utils/test/media-upload.js b/packages/editor/src/utils/test/media-upload.js index 7dac8a422c3530..66c0ff475f7e20 100644 --- a/packages/editor/src/utils/test/media-upload.js +++ b/packages/editor/src/utils/test/media-upload.js @@ -11,10 +11,6 @@ jest.mock( '@wordpress/media-utils', () => ( { uploadMedia: jest.fn(), } ) ); -jest.mock( '@wordpress/upload-media', () => ( { - isClientSideMediaSupported: jest.fn( () => false ), -} ) ); - jest.mock( '@wordpress/core-data', () => ( { store: { name: 'core' }, } ) ); @@ -23,6 +19,9 @@ jest.mock( '../../store', () => ( { store: { name: 'core/editor' }, } ) ); +const mockLockPostSaving = jest.fn(); +const mockLockPostAutosaving = jest.fn(); + jest.mock( '@wordpress/data', () => ( { select: jest.fn( () => ( { getCurrentPost: () => ( { id: 1 } ), @@ -33,9 +32,9 @@ jest.mock( '@wordpress/data', () => ( { } ) ), dispatch: jest.fn( () => ( { receiveEntityRecords: jest.fn(), - lockPostSaving: jest.fn(), + lockPostSaving: mockLockPostSaving, unlockPostSaving: jest.fn(), - lockPostAutosaving: jest.fn(), + lockPostAutosaving: mockLockPostAutosaving, unlockPostAutosaving: jest.fn(), } ) ), } ) ); @@ -43,9 +42,10 @@ jest.mock( '@wordpress/data', () => ( { describe( 'mediaUpload', () => { beforeEach( () => { reset(); + jest.clearAllMocks(); } ); - it( 'registers files with the upload progress tracker', () => { + it( 'registers files with the upload progress tracker and locks saving', () => { const file = new File( [ 'content' ], 'photo.jpg', { type: 'image/jpeg', } ); @@ -57,19 +57,23 @@ describe( 'mediaUpload', () => { completed: 0, pending: [ 'photo.jpg' ], } ); + expect( mockLockPostSaving ).toHaveBeenCalled(); + expect( mockLockPostAutosaving ).toHaveBeenCalled(); } ); - it( 'skips tracker registration when the caller tracks progress itself', () => { - // The upload-media queue calls this wrapper as its server transport - // and already counts its own queue items for the progress snackbar; - // registering the same file here would double-count it - // (see gutenberg#80369). + it( 'skips tracking and save locking for transport-only calls', () => { + // The upload-media queue calls this wrapper as its server transport; + // it already counts its own queue items for the progress snackbar + // (registering the same file here would double-count it, see + // gutenberg#80369) and locks saving via useUploadSaveLock. const file = new File( [ 'content' ], 'photo.jpg', { type: 'image/jpeg', } ); - mediaUpload( { filesList: [ file ], skipTracking: true } ); + mediaUpload( { filesList: [ file ], isTransportOnly: true } ); expect( getState() ).toBeNull(); + expect( mockLockPostSaving ).not.toHaveBeenCalled(); + expect( mockLockPostAutosaving ).not.toHaveBeenCalled(); } ); } ); diff --git a/packages/upload-media/CHANGELOG.md b/packages/upload-media/CHANGELOG.md index 670e4c94314912..371067b77bf2f5 100644 --- a/packages/upload-media/CHANGELOG.md +++ b/packages/upload-media/CHANGELOG.md @@ -12,7 +12,7 @@ ### Bug Fixes -- Pass `skipTracking: true` to the `mediaUpload` setting when the queue uploads a file, so consumers that track upload progress themselves don't count the same file twice ([#80369](https://github.com/WordPress/gutenberg/issues/80369)). +- Pass `isTransportOnly: true` to the `mediaUpload` setting when the queue uploads a file, so consumers that manage the upload lifecycle themselves (progress tracking, save locking) don't handle the same file twice ([#80369](https://github.com/WordPress/gutenberg/issues/80369)). ## 0.36.0 (2026-07-14) diff --git a/packages/upload-media/src/store/private-actions.ts b/packages/upload-media/src/store/private-actions.ts index c91cb12bfd77de..07d52898323a57 100644 --- a/packages/upload-media/src/store/private-actions.ts +++ b/packages/upload-media/src/store/private-actions.ts @@ -1034,10 +1034,11 @@ export function uploadItem( id: QueueItemId ) { filesList: [ item.file ], additionalData: item.additionalData, signal: item.abortController?.signal, - // The queue's own items drive upload progress UI; without this, - // consumers that track uploads themselves (e.g. the editor's - // progress snackbar) would count this file a second time. - skipTracking: true, + // The queue's own items drive upload progress UI and save + // locking; without this, consumers that track uploads themselves + // (e.g. the editor's progress snackbar) would count this file a + // second time. + isTransportOnly: true, onFileChange: ( [ attachment ] ) => { if ( attachment && ! isBlobURL( attachment.url ) ) { finishUpload( attachment ); diff --git a/packages/upload-media/src/store/test/private-actions.js b/packages/upload-media/src/store/test/private-actions.js index c098529a945edd..bfe500958f0eac 100644 --- a/packages/upload-media/src/store/test/private-actions.js +++ b/packages/upload-media/src/store/test/private-actions.js @@ -1415,7 +1415,7 @@ describe( 'private actions', () => { } ); describe( 'uploadItem', () => { - it( 'flags the transport call so consumers skip their own progress tracking', async () => { + it( 'flags the transport call so consumers skip their own lifecycle handling', async () => { // The queue already counts its items for progress UI; the // `mediaUpload` callback it delegates the server upload to must // not count the same file again (see gutenberg#80369). @@ -1440,7 +1440,7 @@ describe( 'private actions', () => { expect( mediaUpload ).toHaveBeenCalledWith( expect.objectContaining( { filesList: [ file ], - skipTracking: true, + isTransportOnly: true, } ) ); } ); diff --git a/packages/upload-media/src/store/types.ts b/packages/upload-media/src/store/types.ts index 92ba76fa07a3e8..f7b48e54d61bae 100644 --- a/packages/upload-media/src/store/types.ts +++ b/packages/upload-media/src/store/types.ts @@ -174,9 +174,9 @@ interface UploadMediaArgs { wpAllowedMimeTypes?: Record< string, string > | null; // Abort signal. signal?: AbortSignal; - // Whether the caller tracks upload progress itself, so the handler - // should skip its own progress tracking to avoid double-counting. - skipTracking?: boolean; + // Whether the caller owns the upload lifecycle UX (progress tracking, + // save locking) and uses the handler only as its server transport. + isTransportOnly?: boolean; } /**