diff --git a/packages/js/product-editor/changelog/fix-product-editor-blank-flash b/packages/js/product-editor/changelog/fix-product-editor-blank-flash new file mode 100644 index 00000000000..4585e5b0381 --- /dev/null +++ b/packages/js/product-editor/changelog/fix-product-editor-blank-flash @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Product Editor loading state now shows until form is displayed. No more blank flash of white. diff --git a/packages/js/product-editor/src/components/block-editor/block-editor.tsx b/packages/js/product-editor/src/components/block-editor/block-editor.tsx index cbc908b708f..1d47d24b96a 100644 --- a/packages/js/product-editor/src/components/block-editor/block-editor.tsx +++ b/packages/js/product-editor/src/components/block-editor/block-editor.tsx @@ -46,6 +46,7 @@ import { ModalEditor } from '../modal-editor'; import { ProductEditorSettings } from '../editor'; import { BlockEditorProps } from './types'; import { ProductTemplate } from '../../types'; +import { LoadingState } from './loading-state'; function getLayoutTemplateId( productTemplate: ProductTemplate | undefined, @@ -62,11 +63,13 @@ function getLayoutTemplateId( // Fallback to simple product if no layout template is set. return 'simple-product'; } + export function BlockEditor( { context, settings: _settings, postType, productId, + setIsEditorLoading, }: BlockEditorProps ) { useConfirmUnsavedProductChanges( postType ); @@ -142,8 +145,14 @@ export function BlockEditor( { const { updateEditorSettings } = useDispatch( 'core/editor' ); + const isEditorLoading = + ! layoutTemplate || + // variations don't have a product template + ( postType !== 'product_variation' && ! productTemplate ) || + productId === -1; + useLayoutEffect( () => { - if ( ! layoutTemplate ) { + if ( isEditorLoading ) { return; } @@ -159,6 +168,8 @@ export function BlockEditor( { productTemplate, } as Partial< ProductEditorSettings > ); + setIsEditorLoading( isEditorLoading ); + // We don't need to include onChange or updateEditorSettings in the dependencies, // since we get new instances of them on every render, which would cause an infinite loop. // @@ -176,10 +187,6 @@ export function BlockEditor( { const { closeModalEditor } = useDispatch( productEditorUiStore ); - if ( ! blocks ) { - return null; - } - if ( isModalEditorOpen ) { return ( - + { isEditorLoading ? ( + + ) : ( + + ) } { /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */ } diff --git a/packages/js/product-editor/src/components/block-editor/loading-state/index.ts b/packages/js/product-editor/src/components/block-editor/loading-state/index.ts new file mode 100644 index 00000000000..b9af07b0b02 --- /dev/null +++ b/packages/js/product-editor/src/components/block-editor/loading-state/index.ts @@ -0,0 +1 @@ +export * from './loading-state'; diff --git a/packages/js/product-editor/src/components/block-editor/loading-state/loading-state.tsx b/packages/js/product-editor/src/components/block-editor/loading-state/loading-state.tsx new file mode 100644 index 00000000000..59658b107b2 --- /dev/null +++ b/packages/js/product-editor/src/components/block-editor/loading-state/loading-state.tsx @@ -0,0 +1,61 @@ +/** + * External dependencies + */ +import { createElement } from '@wordpress/element'; + +export function LoadingState() { + return ( +