Skip to content
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
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: 0 additions & 1 deletion packages/dependency-extraction-webpack-plugin/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const BUNDLED_PACKAGES = [
'@wordpress/interface',
'@wordpress/sync',
'@wordpress/undo-manager',
'@wordpress/upload-media',
'@wordpress/fields',
'@wordpress/views',
'@wordpress/ui',
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,
] );
}
16 changes: 11 additions & 5 deletions packages/editor/src/utils/media-upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ export default function mediaUpload( {
allowedTypes,
filesList,
onFileChange: ( file ) => {
if ( ! imageIsUploading ) {
setSaveLock();
} else {
clearSaveLock();
// When client-side media processing is enabled, save locking
// is handled by useUploadSaveLock in the editor provider.
if ( ! window.__experimentalMediaProcessing ) {
if ( ! imageIsUploading ) {
setSaveLock();
} else {
clearSaveLock();
}
}
onFileChange?.( file );

Expand All @@ -107,7 +111,9 @@ export default function mediaUpload( {
},
maxUploadFileSize,
onError: ( { message } ) => {
clearSaveLock();
if ( ! window.__experimentalMediaProcessing ) {
clearSaveLock();
}
onError( message );
},
wpAllowedMimeTypes,
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
10 changes: 9 additions & 1 deletion packages/upload-media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@
},
"./package.json": "./package.json"
},
"wpScript": true,
"types": "build-types",
"sideEffects": false,
"sideEffects": [
"src/index.ts",
"src/store/index.ts",
"build/index.cjs",
"build/store/index.cjs",
"build-module/index.mjs",
"build-module/store/index.mjs"
],
"dependencies": {
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/blob": "file:../blob",
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 );
dispatch.revokeBlobUrls( id );

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