Skip to content

Commit

Permalink
Don't call unlock at module level
Browse files Browse the repository at this point in the history
Fixes unit tests failing at
packages/editor/src/components/document-outline
  • Loading branch information
mcsf committed Jul 13, 2023
1 parent 1bddc35 commit 4382c18
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/core-data/src/footnotes/get-rich-text-values-cached.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
*/
import { unlock } from '../private-apis';

const { getRichTextValues } = unlock( blockEditorPrivateApis );
// Avoid calling `unlock` at the module level, deferring the call until needed
// in `getRichTextValuesCached`.
let unlockedApis;

const cache = new WeakMap();

export default function getRichTextValuesCached( block ) {
if ( ! unlockedApis ) {
unlockedApis = unlock( blockEditorPrivateApis );
}

if ( ! cache.has( block ) ) {
const values = getRichTextValues( [ block ] );
const values = unlockedApis.getRichTextValues( [ block ] );
cache.set( block, values );
}
return cache.get( block );
Expand Down

0 comments on commit 4382c18

Please sign in to comment.