Skip to content
Merged
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
34 changes: 31 additions & 3 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } ),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
}
Expand Down
Loading