Skip to content

Commit

Permalink
Fix useInstanceId hook references
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Sep 30, 2024
1 parent cd701e9 commit 760be79
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,11 @@ function useDuotoneStyles( {
}, [ isValidFilter, blockElement, colors ] );
}

// Used for generating the instance ID
const DUOTONE_BLOCK_PROPS_REFERENCE = {};

function useBlockProps( { clientId, name, style } ) {
const id = useInstanceId( useBlockProps );
const id = useInstanceId( DUOTONE_BLOCK_PROPS_REFERENCE );
const selector = useMemo( () => {
const blockType = getBlockType( name );

Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/hooks/layout-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
GridItemMovers,
} from '../components/grid';

// Used for generating the instance ID
const LAYOUT_CHILD_BLOCK_PROPS_REFERENCE = {};

function useBlockPropsChildLayoutStyles( { style } ) {
const shouldRenderChildLayoutStyles = useSelect( ( select ) => {
return ! select( blockEditorStore ).getSettings().disableLayoutStyles;
Expand All @@ -32,7 +35,7 @@ function useBlockPropsChildLayoutStyles( { style } ) {
} = layout;
const parentLayout = useLayout() || {};
const { columnCount, minimumColumnWidth } = parentLayout;
const id = useInstanceId( useBlockPropsChildLayoutStyles );
const id = useInstanceId( LAYOUT_CHILD_BLOCK_PROPS_REFERENCE );
const selector = `.wp-container-content-${ id }`;

// Check that the grid layout attributes are of the correct type, so that we don't accidentally
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/hooks/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ export default {
},
};

// Used for generating the instance ID
const POSITION_BLOCK_PROPS_REFERENCE = {};

function useBlockProps( { name, style } ) {
const hasPositionBlockSupport = hasBlockSupport(
name,
Expand All @@ -318,7 +321,7 @@ function useBlockProps( { name, style } ) {
const isPositionDisabled = useIsPositionDisabled( { name } );
const allowPositionStyles = hasPositionBlockSupport && ! isPositionDisabled;

const id = useInstanceId( useBlockProps );
const id = useInstanceId( POSITION_BLOCK_PROPS_REFERENCE );

// Higher specificity to override defaults in editor UI.
const positionSelector = `.wp-container-${ id }.wp-container-${ id }`;
Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ const getNodeText = ( node: React.ReactNode ): string => {

const EMPTY_FILTERED_OPTIONS: KeyedOption[] = [];

// Used for generating the instance ID
const AUTOCOMPLETE_HOOK_REFERENCE = {};

export function useAutocomplete( {
record,
onChange,
onReplace,
completers,
contentRef,
}: UseAutocompleteProps ) {
const instanceId = useInstanceId( useAutocomplete );
const instanceId = useInstanceId( AUTOCOMPLETE_HOOK_REFERENCE );
const [ selectedIndex, setSelectedIndex ] = useState( 0 );

const [ filteredOptions, setFilteredOptions ] = useState<
Expand Down

0 comments on commit 760be79

Please sign in to comment.