Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Notes } from './notes';
import { store as editorStore } from '../../store';
import { AddNoteMenuItem } from './add-note-menu-item';
import { NoteAvatarIndicator } from './note-indicator-toolbar';
import { useGlobalStylesContext } from '../global-styles-provider';
import { useGlobalStyles } from '../global-styles';
import { useNoteThreads, useEnableFloatingSidebar } from './hooks';
import { getNoteIdsFromMetadata, pickPrimaryNote } from './utils';
import PostTypeSupportCheck from '../post-type-support-check';
Expand Down Expand Up @@ -143,7 +143,7 @@ function NotesSidebar( { postId } ) {
);

// Get the global styles to set the background color of the sidebar.
const { merged: GlobalStyles } = useGlobalStylesContext();
const { merged: GlobalStyles } = useGlobalStyles();
const backgroundColor = GlobalStyles?.styles?.color?.background;

// Surface one thread for the avatar indicator.
Expand Down
207 changes: 0 additions & 207 deletions packages/editor/src/components/global-styles-provider/index.js

This file was deleted.

26 changes: 26 additions & 0 deletions packages/editor/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ function useGlobalStylesUserConfig() {

let record;

/*
* Ensure that the global styles ID request is complete by testing `_globalStylesId`,
* before firing off the `canUser` OPTIONS request for user capabilities, otherwise it will
* fetch `/wp/v2/global-styles` instead of `/wp/v2/global-styles/{id}`.
* NOTE: Please keep in sync any preload paths sent to `block_editor_rest_api_preload()`,
* or set using the `block_editor_rest_api_preload_paths` filter, if this changes.
*/
const userCanEditGlobalStyles = _globalStylesId
? canUser( 'update', {
kind: 'root',
Expand All @@ -45,8 +52,21 @@ function useGlobalStylesUserConfig() {

if (
_globalStylesId &&
/*
* Test that the OPTIONS request for user capabilities is complete
* before fetching the global styles entity record.
* This is to avoid fetching the global styles entity unnecessarily.
*/
typeof userCanEditGlobalStyles === 'boolean'
) {
/*
* Fetch the global styles entity record based on the user's capabilities.
* The default context is `edit` for users who can edit global styles.
* Otherwise, the context is `view`.
* NOTE: There is an equivalent conditional check using `current_user_can()` in the backend
* to preload the global styles entity. Please keep in sync any preload paths sent to `block_editor_rest_api_preload()`,
* or set using `block_editor_rest_api_preload_paths` filter, if this changes.
*/
if ( userCanEditGlobalStyles ) {
record = getEditedEntityRecord(
'root',
Expand Down Expand Up @@ -110,6 +130,12 @@ function useGlobalStylesUserConfig() {
}, [ settings, styles, _links ] );

const setConfig = useCallback(
/**
* Set the global styles config.
* @param {Function|Object} callbackOrObject If the callbackOrObject is a function, pass the current config to the callback so the consumer can merge values.
* Otherwise, overwrite the current config with the incoming object.
* @param {Object} options Options for editEntityRecord Core selector.
*/
( callbackOrObject, options = {} ) => {
const record = getEditedEntityRecord(
'root',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { default as mediaFinalize } from '../../utils/media-finalize';
import { default as mediaDelete } from '../../utils/media-delete';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { useGlobalStylesContext } from '../global-styles-provider';
import { useGlobalStyles } from '../global-styles';

const { store: mediaEditorStore } = unlock( mediaEditorPrivateApis );

Expand Down Expand Up @@ -235,7 +235,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
[ postType, postId, isLargeViewport, renderingMode ]
);

const { merged: mergedGlobalStyles } = useGlobalStylesContext();
const { merged: mergedGlobalStyles } = useGlobalStyles();
const globalStylesData = mergedGlobalStyles.styles ?? EMPTY_OBJECT;
const globalStylesLinksData = mergedGlobalStyles._links ?? EMPTY_OBJECT;

Expand Down
Loading