Skip to content

Commit

Permalink
Fix useInstanceId hook references (#65733)
Browse files Browse the repository at this point in the history
Co-authored-by: tyxla <[email protected]>
Co-authored-by: mirka <[email protected]>
  • Loading branch information
3 people committed Sep 30, 2024
1 parent 6f8a67a commit 20dc9b7
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

1 comment on commit 20dc9b7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 20dc9b7.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11103609147
📝 Reported issues:

Please sign in to comment.