Skip to content
Closed
Prev Previous commit
Next Next commit
Revert changes to slot fill - remove slot fill filtering from slot co…
…mponent
  • Loading branch information
jeryj committed Sep 5, 2025
commit b15e32e65bad7a69265ce6b84804da66c734fbb4
19 changes: 6 additions & 13 deletions packages/block-editor/src/components/block-controls/groups.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
/**
* WordPress dependencies
*/
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';

const { createPrivateSlotFill } = unlock( componentsPrivateApis );

const BlockControlsDefault = createPrivateSlotFill( 'BlockControls' );
const BlockControlsBlock = createPrivateSlotFill( 'BlockControlsBlock' );
const BlockControlsInline = createPrivateSlotFill( 'BlockFormatControls' );
const BlockControlsOther = createPrivateSlotFill( 'BlockControlsOther' );
const BlockControlsParent = createPrivateSlotFill( 'BlockControlsParent' );
const BlockControlsDefault = createSlotFill( 'BlockControls' );
const BlockControlsBlock = createSlotFill( 'BlockControlsBlock' );
const BlockControlsInline = createSlotFill( 'BlockFormatControls' );
const BlockControlsOther = createSlotFill( 'BlockControlsOther' );
const BlockControlsParent = createSlotFill( 'BlockControlsParent' );

const groups = {
default: BlockControlsDefault,
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/private-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { kebabCase, normalizeTextString } from './utils/strings';
import { withIgnoreIMEEvents } from './utils/with-ignore-ime-events';
import { lock } from './lock-unlock';
import Badge from './badge';
import { createPrivateSlotFill } from './slot-fill';

import { DateCalendar, DateRangeCalendar, TZDate } from './calendar';
import {
Expand All @@ -36,5 +35,4 @@ lock( privateApis, {
ValidatedNumberControl,
ValidatedTextControl,
ValidatedToggleControl,
createPrivateSlotFill,
} );
25 changes: 0 additions & 25 deletions packages/components/src/slot-fill/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import type {
DistributiveOmit,
FillComponentProps,
SlotComponentProps,
PrivateSlotComponentProps,
SlotFillProviderProps,
SlotKey,
} from './types';
Expand Down Expand Up @@ -97,27 +96,3 @@ export function createSlotFill( key: SlotKey ) {
Slot: SlotComponent,
};
}

export function createPrivateSlotFill( key: SlotKey ) {
const baseName = typeof key === 'symbol' ? key.description : key;
const FillComponent = ( props: Omit< FillComponentProps, 'name' > ) => (
<Fill name={ key } { ...props } />
);
FillComponent.displayName = `${ baseName }Fill`;

const SlotComponent = (
props: DistributiveOmit< PrivateSlotComponentProps, 'name' >
) => <Slot name={ key } { ...props } />;
SlotComponent.displayName = `${ baseName }Slot`;
/**
* @deprecated 6.8.0
* Please use `slotFill.name` instead of `slotFill.Slot.__unstableName`.
*/
SlotComponent.__unstableName = key;

return {
name: key,
Fill: FillComponent,
Slot: SlotComponent,
};
}
15 changes: 3 additions & 12 deletions packages/components/src/slot-fill/slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
* Internal dependencies
*/
import SlotFillContext from './context';
import type { SlotComponentProps, PrivateSlotComponentProps } from './types';
import type { SlotComponentProps } from './types';

/**
* Whether the argument is a function.
Expand Down Expand Up @@ -48,17 +48,11 @@ function addKeysToChildren( children: ReactNode ) {
} );
}

function Slot(
props: Omit<
SlotComponentProps | PrivateSlotComponentProps,
'bubblesVirtually'
>
) {
function Slot( props: Omit< SlotComponentProps, 'bubblesVirtually' > ) {
const registry = useContext( SlotFillContext );
const instanceRef = useRef( {} );

const { name, children, fillProps = {} } = props;
const filter = ( props as any ).filter;

useLayoutEffect( () => {
const instance = instanceRef.current;
Expand All @@ -74,10 +68,7 @@ function Slot(
fills = [];
}

// Apply filter function if provided (private API)
const filteredFills = filter ? fills.filter( filter ) : fills;

const renderedFills = filteredFills
const renderedFills = fills
.map( ( fill ) => {
const fillChildren = isFunction( fill.children )
? fill.children( fillProps )
Expand Down
120 changes: 52 additions & 68 deletions packages/components/src/slot-fill/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,75 +30,59 @@ type SlotPropBase = {
fillProps?: FillProps;
};

export type FillFilter = ( fill: {
instance: FillInstance;
children: FillChildren;
} ) => boolean;

// Base slot props with bubblesVirtually discrimination
type SlotPropsWithBubblesVirtually = SlotPropBase & {
/**
* By default, events will bubble to their parents on the DOM hierarchy (native event bubbling).
* If set to true, events will bubble to their virtual parent in the React elements hierarchy instead,
* also accept an optional `className`, `id`, etc. to add to the slot container.
*/
bubblesVirtually: true;

/**
* A function that returns nodes to be rendered.
* Supported only when `bubblesVirtually` is `false`.
*/
children?: never;

/**
* Additional className for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
className?: string;

/**
* Additional styles for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
style?: React.CSSProperties;
};

type SlotPropsWithoutBubblesVirtually = SlotPropBase & {
/**
* By default, events will bubble to their parents on the DOM hierarchy (native event bubbling).
* If set to true, events will bubble to their virtual parent in the React elements hierarchy instead,
* also accept an optional `className`, `id`, etc. to add to the slot container.
*/
bubblesVirtually?: false;

/**
* A function that returns nodes to be rendered.
* Supported only when `bubblesVirtually` is `false`.
*/
children?: ( fills: ReactNode ) => ReactNode;

/**
* Additional className for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
className?: never;

/**
* Additional styles for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
style?: never;
};

// Public slot props (no filtering)
export type SlotComponentProps =
| SlotPropsWithBubblesVirtually
| SlotPropsWithoutBubblesVirtually;

// Private slot props (with filtering)
export type PrivateSlotComponentProps =
| ( SlotPropsWithBubblesVirtually & { filter?: FillFilter } )
| ( SlotPropsWithoutBubblesVirtually & { filter?: FillFilter } );
| ( SlotPropBase & {
/**
* By default, events will bubble to their parents on the DOM hierarchy (native event bubbling).
* If set to true, events will bubble to their virtual parent in the React elements hierarchy instead,
* also accept an optional `className`, `id`, etc. to add to the slot container.
*/
bubblesVirtually: true;

/**
* A function that returns nodes to be rendered.
* Supported only when `bubblesVirtually` is `false`.
*/
children?: never;

/**
* Additional className for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
className?: string;

/**
* Additional styles for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
style?: React.CSSProperties;
} )
| ( SlotPropBase & {
/**
* By default, events will bubble to their parents on the DOM hierarchy (native event bubbling).
* If set to true, events will bubble to their virtual parent in the React elements hierarchy instead,
* also accept an optional `className`, `id`, etc. to add to the slot container.
*/
bubblesVirtually?: false;

/**
* A function that returns nodes to be rendered.
* Supported only when `bubblesVirtually` is `false`.
*/
children?: ( fills: ReactNode ) => ReactNode;

/**
* Additional className for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
className?: never;

/**
* Additional styles for the `Slot` component.
* Supported only when `bubblesVirtually` is `true`.
*/
style?: never;
} );

export type FillChildren =
| ReactNode
Expand Down