diff --git a/packages/edit-post/src/index.js b/packages/edit-post/src/index.js index edb5d5979d53b3..8bb6ddaf437dc3 100644 --- a/packages/edit-post/src/index.js +++ b/packages/edit-post/src/index.js @@ -194,7 +194,6 @@ async function preloadResolutions( postType, postId ) { core.__experimentalGetCurrentThemeBaseGlobalStyles(), core.__experimentalGetCurrentThemeGlobalStylesVariations(), core.getEntityRecord( 'root', '__unstableBase' ), - core.getEntityRecord( 'root', 'site' ), core.canUser( 'read', { kind: 'root', name: 'site' } ), core.canUser( 'create', { kind: 'postType', name: 'attachment' } ), core.canUser( 'create', { kind: 'postType', name: 'page' } ), @@ -238,12 +237,16 @@ async function preloadResolutions( postType, postId ) { // Phase 2: read derived data out of state. const tasks = []; + + if ( coreSelect.canUser( 'read', { kind: 'root', name: 'site' } ) ) { + tasks.push( core.getEntityRecord( 'root', 'site' ) ); + } + const globalStylesId = coreSelect.__experimentalGetCurrentGlobalStylesId(); if ( globalStylesId ) { tasks.push( - core.getEntityRecord( 'root', 'globalStyles', globalStylesId ), - core.canUser( 'read', { + core.canUser( 'update', { kind: 'root', name: 'globalStyles', id: globalStylesId, @@ -279,6 +282,31 @@ async function preloadResolutions( postType, postId ) { if ( tasks.length ) { await Promise.all( tasks ); } + + // Phase 3: requests whose capability check only resolved in phase 2. + if ( globalStylesId ) { + if ( + coreSelect.canUser( 'update', { + kind: 'root', + name: 'globalStyles', + id: globalStylesId, + } ) + ) { + await core.getEntityRecord( + 'root', + 'globalStyles', + globalStylesId + ); + } else { + // Fetch for non-admin users using view context. + await core.getEntityRecord( + 'root', + 'globalStyles', + globalStylesId, + { context: 'view' } + ); + } + } } catch { // Resolver failures here would also surface on demand; don't block render. }