Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function mediaUpload(
}
) {
void registry.dispatch( uploadStore ).addItems( {
files: filesList,
files: Array.from( filesList ),
onChange: onFileChange,
onSuccess,
onBatchSuccess,
Expand Down
1 change: 1 addition & 0 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"@wordpress/reusable-blocks": "file:../reusable-blocks",
"@wordpress/rich-text": "file:../rich-text",
"@wordpress/server-side-render": "file:../server-side-render",
"@wordpress/upload-media": "file:../upload-media",
"@wordpress/url": "file:../url",
"@wordpress/warning": "file:../warning",
"@wordpress/wordcount": "file:../wordcount",
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import DisableNonPageContentBlocks from './disable-non-page-content-blocks';
import NavigationBlockEditingMode from './navigation-block-editing-mode';
import { useHideBlocksFromInserter } from './use-hide-blocks-from-inserter';
import useCommands from '../commands';
import useUploadSaveLock from './use-upload-save-lock';
import BlockRemovalWarnings from '../block-removal-warnings';
import StartPageOptions from '../start-page-options';
import KeyboardShortcutHelpModal from '../keyboard-shortcut-help-modal';
Expand Down Expand Up @@ -352,6 +353,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
// Register the editor commands.
useCommands();

// Lock post saving when media uploads are in progress (experimental feature).
useUploadSaveLock();

if ( ! isReady || ! mode ) {
return null;
}
Expand Down
66 changes: 66 additions & 0 deletions packages/editor/src/components/provider/use-upload-save-lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { store as uploadStore } from '@wordpress/upload-media';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';

const LOCK_NAME = 'upload-in-progress';

/**
* A hook that locks post saving and autosaving while media uploads are in progress.
* This prevents users from publishing or saving while files are still uploading.
*
* Only active when the experimental media processing feature is enabled.
*/
export default function useUploadSaveLock() {
const isExperimentEnabled = window.__experimentalMediaProcessing;

const isUploading = useSelect(
( select ) => {
if ( ! isExperimentEnabled ) {
return false;
}
return select( uploadStore ).isUploading();
},
[ isExperimentEnabled ]
);

const {
lockPostSaving,
unlockPostSaving,
lockPostAutosaving,
unlockPostAutosaving,
} = useDispatch( editorStore );

useEffect( () => {
if ( ! isExperimentEnabled ) {
return;
}

if ( isUploading ) {
lockPostSaving( LOCK_NAME );
lockPostAutosaving( LOCK_NAME );
} else {
unlockPostSaving( LOCK_NAME );
unlockPostAutosaving( LOCK_NAME );
}

return () => {
unlockPostSaving( LOCK_NAME );
unlockPostAutosaving( LOCK_NAME );
};
}, [
isExperimentEnabled,
isUploading,
lockPostSaving,
unlockPostSaving,
lockPostAutosaving,
unlockPostAutosaving,
] );
}
6 changes: 6 additions & 0 deletions packages/editor/src/utils/media-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ export default function mediaUpload( {
? currentPost.id
: currentPost?.wp_id;
const setSaveLock = () => {
if ( window.__experimentalMediaProcessing ) {
return; // Skip - handled by useUploadSaveLock in editor provider
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit (feel free to ignore, it really doesn't matter), but we could have a single check in this file by moving these checks down to the onFileChange callback before calling setSaveLock and clearSaveLock, rather than have the check inside these functions.

Also, not for this PR, but when we get to #74827 (implement WebAssembly support detection and fallbacks) we'll have a need for a shouldEnableClientSideMediaProcessing function in the editor package, too. Or alternately, it could be part of media-upload as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consolidated check logic in 84a4961

lockPostSaving( lockKey );
lockPostAutosaving( lockKey );
imageIsUploading = true;
};

const postData = currentPostId ? { post: currentPostId } : {};
const clearSaveLock = () => {
if ( window.__experimentalMediaProcessing ) {
return; // Skip - handled by useUploadSaveLock in editor provider
}
unlockPostSaving( lockKey );
unlockPostAutosaving( lockKey );
imageIsUploading = false;
Expand Down
1 change: 1 addition & 0 deletions packages/editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
{ "path": "../private-apis" },
{ "path": "../rich-text" },
{ "path": "../url" },
{ "path": "../upload-media" },
{ "path": "../warning" },
{ "path": "../wordcount" }
]
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-media/src/store/private-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function processItem( id: QueueItemId ) {
onSuccess?.( [ attachment ] );
}

// dispatch.removeItem( id );
dispatch.removeItem( id );
Comment thread
adamsilverstein marked this conversation as resolved.
Resolved
dispatch.revokeBlobUrls( id );

if ( batchId && select.isBatchUploaded( batchId ) ) {
Expand Down
Loading