Skip to content

Commit b501bf5

Browse files
Block editor: remove the unused element-fold axis from the inherited-value builder
Nothing in the shipping product ever passed an `element` to the inherited-value builder or its hooks, so the entire element-fold path was dead. Remove the `element` parameter, `pickLayerElementContribution`, `getElementObject`, the element-scoped contribution entries in both the base and state passes, and the `rootElement`/`blockElement`/`blockVariationElement` source descriptors. Element styles still surface through the `elements` passthrough that keeps `inheritedValue.elements.link.color.text` working, which is what the panels actually read. Tests are updated to assert that nested passthrough shape instead of the removed fold, and the dead `rootElement` entry is dropped from the dimensions panel's non-cascading layer set.
1 parent 9f542bc commit b501bf5

4 files changed

Lines changed: 42 additions & 311 deletions

File tree

packages/block-editor/src/components/global-styles/build-inherited-value.js

Lines changed: 8 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ const SOURCE_DESCRIPTORS = {
8888
breadcrumb: [ SOURCE_BREADCRUMB_PARTS.styles ],
8989
layer: 'root',
9090
},
91-
rootElement: {
92-
breadcrumb: [
93-
SOURCE_BREADCRUMB_PARTS.styles,
94-
SOURCE_BREADCRUMB_PARTS.elements,
95-
],
96-
layer: 'rootElement',
97-
},
9891
block: {
9992
breadcrumb: [
10093
SOURCE_BREADCRUMB_PARTS.styles,
@@ -103,15 +96,6 @@ const SOURCE_DESCRIPTORS = {
10396
],
10497
layer: 'block',
10598
},
106-
blockElement: {
107-
breadcrumb: [
108-
SOURCE_BREADCRUMB_PARTS.styles,
109-
SOURCE_BREADCRUMB_PARTS.blocks,
110-
SOURCE_BREADCRUMB_PARTS.blockName,
111-
SOURCE_BREADCRUMB_PARTS.elements,
112-
],
113-
layer: 'blockElement',
114-
},
11599
blockVariation: {
116100
breadcrumb: [
117101
SOURCE_BREADCRUMB_PARTS.styles,
@@ -122,38 +106,24 @@ const SOURCE_DESCRIPTORS = {
122106
],
123107
layer: 'blockVariation',
124108
},
125-
blockVariationElement: {
126-
breadcrumb: [
127-
SOURCE_BREADCRUMB_PARTS.styles,
128-
SOURCE_BREADCRUMB_PARTS.blocks,
129-
SOURCE_BREADCRUMB_PARTS.blockName,
130-
SOURCE_BREADCRUMB_PARTS.variations,
131-
SOURCE_BREADCRUMB_PARTS.variationName,
132-
SOURCE_BREADCRUMB_PARTS.elements,
133-
],
134-
layer: 'blockVariationElement',
135-
},
136109
};
137110

138111
function createSourceDescriptor(
139112
type,
140-
{ blockName, variation, element, blockStyles } = {}
113+
{ blockName, variation, blockStyles } = {}
141114
) {
142115
const descriptor = SOURCE_DESCRIPTORS[ type ];
143116
if ( ! descriptor ) {
144117
return null;
145118
}
146119
return {
147120
...descriptor,
148-
breadcrumb: element
149-
? [ ...descriptor.breadcrumb, element ]
150-
: [ ...descriptor.breadcrumb ],
121+
breadcrumb: [ ...descriptor.breadcrumb ],
151122
blockName: blockName ?? null,
152123
variation: variation ?? null,
153124
variationTitle:
154125
blockStyles?.find( ( style ) => style.name === variation )?.label ??
155126
null,
156-
element: element ?? null,
157127
};
158128
}
159129

@@ -236,8 +206,7 @@ function isRefObject( v ) {
236206
* leaves and sub-trees that are not tree-structural and not the
237207
* `elements` sub-tree itself. The `elements` sub-tree IS preserved as a
238208
* passthrough on the final payload so panels that read e.g.
239-
* `inheritedValue.elements.link.color.text` keep working; it just does
240-
* not participate in the element-scoped fold.
209+
* `inheritedValue.elements.link.color.text` keep working.
241210
*
242211
* Does not recurse or clone; the returned contribution references the
243212
* original layer's sub-objects. The deep-merge step copies them into a
@@ -269,37 +238,6 @@ function pickLayerRootContribution( layer ) {
269238
return Object.keys( contribution ).length === 0 ? null : contribution;
270239
}
271240

272-
/**
273-
* Pick the element-scope contribution from `layer.elements[element]`.
274-
* Returns a plain-object "layer-shaped" contribution — same top-level
275-
* keys as a normal layer — so it can be merged in the same pipeline as
276-
* root-scope contributions, inheriting deep-merge semantics.
277-
*
278-
* @param {Object} layer Raw styles layer.
279-
* @param {?string} element Element tag (e.g. `h2`, `link`).
280-
* @return {Object|null} Element-scope contribution, or `null` when no leaves contribute.
281-
*/
282-
function pickLayerElementContribution( layer, element ) {
283-
if ( ! element || ! layer || ! layer.elements ) {
284-
return null;
285-
}
286-
const folded = layer.elements[ element ];
287-
if ( ! folded || typeof folded !== 'object' || Array.isArray( folded ) ) {
288-
return null;
289-
}
290-
const contribution = {};
291-
for ( const key of Object.keys( folded ) ) {
292-
if ( TREE_STRUCTURAL_KEYS.has( key ) || key === 'elements' ) {
293-
continue;
294-
}
295-
if ( isExplicitEmpty( folded[ key ] ) ) {
296-
continue;
297-
}
298-
contribution[ key ] = folded[ key ];
299-
}
300-
return Object.keys( contribution ).length === 0 ? null : contribution;
301-
}
302-
303241
/**
304242
* Deep-merge `source` into `target` with the following rules:
305243
* - Plain objects recurse.
@@ -379,22 +317,6 @@ function deepMergeDroppingEmpties(
379317
return target;
380318
}
381319

382-
/**
383-
* Read a layer's `elements[ element ]` sub-object, guarding against
384-
* non-object values.
385-
*
386-
* @param {?Object} layer Raw styles layer.
387-
* @param {?string} element Element tag (e.g. `h2`, `link`, `button`).
388-
* @return {Object|null} The element sub-object, or `null`.
389-
*/
390-
function getElementObject( layer, element ) {
391-
if ( ! layer || ! element ) {
392-
return null;
393-
}
394-
const el = layer.elements?.[ element ];
395-
return el && typeof el === 'object' && ! Array.isArray( el ) ? el : null;
396-
}
397-
398320
/**
399321
* Resolve the state-scoped slice of a layer-shaped object for the selected
400322
* block style state, guarding against nullish inputs.
@@ -420,7 +342,6 @@ function getStateSlice( layerObject, selectedState ) {
420342
*
421343
* @param {Object} args
422344
* @param {string} args.blockName Block name (e.g. `core/heading`).
423-
* @param {?string} [args.element] Element tag to fold (e.g. `h2`, `link`), or null for block-scope only.
424345
* @param {?string} [args.ownVariation] Active block style variation slug, or null.
425346
* @param {Object} [args.globalStyles] The `settings[ globalStylesDataKey ]` payload.
426347
* @param {Array} [args.blockStyles] Registered styles for the block type.
@@ -429,7 +350,6 @@ function getStateSlice( layerObject, selectedState ) {
429350
*/
430351
function computeInheritedValue( {
431352
blockName,
432-
element = null,
433353
ownVariation = null,
434354
globalStyles,
435355
blockStyles = [],
@@ -455,35 +375,21 @@ function computeInheritedValue( {
455375
) ?? null
456376
: null;
457377

458-
// Layers are ordered from low to high precedence. Root-scope and
459-
// element-scope contributions are merged separately so element
460-
// overrides can replace specific leaves without dropping sibling values.
378+
// Layers are ordered from low to high precedence: root defaults, the
379+
// block's own defaults, then the active block style variation. Each
380+
// layer's `elements` sub-tree is preserved as a passthrough so panels
381+
// can read element styles (e.g. `inheritedValue.elements.link`).
461382
const contributions = [
462383
createContribution(
463384
pickLayerRootContribution( root ),
464385
createSourceDescriptor( 'root' )
465386
),
466-
element
467-
? createContribution(
468-
pickLayerElementContribution( root, element ),
469-
createSourceDescriptor( 'rootElement', { element } )
470-
)
471-
: null,
472387
block
473388
? createContribution(
474389
pickLayerRootContribution( block ),
475390
createSourceDescriptor( 'block', { blockName } )
476391
)
477392
: null,
478-
block && element
479-
? createContribution(
480-
pickLayerElementContribution( block, element ),
481-
createSourceDescriptor( 'blockElement', {
482-
blockName,
483-
element,
484-
} )
485-
)
486-
: null,
487393
variation
488394
? createContribution(
489395
pickLayerRootContribution( variation ),
@@ -494,17 +400,6 @@ function computeInheritedValue( {
494400
} )
495401
)
496402
: null,
497-
variation && element
498-
? createContribution(
499-
pickLayerElementContribution( variation, element ),
500-
createSourceDescriptor( 'blockVariationElement', {
501-
blockName,
502-
variation: ownVariation,
503-
blockStyles,
504-
element,
505-
} )
506-
)
507-
: null,
508403
];
509404

510405
// When a non-default block style state (pseudo and/or responsive
@@ -523,17 +418,6 @@ function computeInheritedValue( {
523418
),
524419
createSourceDescriptor( 'root' )
525420
),
526-
element
527-
? createContribution(
528-
pickLayerRootContribution(
529-
getStateSlice(
530-
getElementObject( root, element ),
531-
selectedState
532-
)
533-
),
534-
createSourceDescriptor( 'rootElement', { element } )
535-
)
536-
: null,
537421
block
538422
? createContribution(
539423
pickLayerRootContribution(
@@ -542,20 +426,6 @@ function computeInheritedValue( {
542426
createSourceDescriptor( 'block', { blockName } )
543427
)
544428
: null,
545-
block && element
546-
? createContribution(
547-
pickLayerRootContribution(
548-
getStateSlice(
549-
getElementObject( block, element ),
550-
selectedState
551-
)
552-
),
553-
createSourceDescriptor( 'blockElement', {
554-
blockName,
555-
element,
556-
} )
557-
)
558-
: null,
559429
variation
560430
? createContribution(
561431
pickLayerRootContribution(
@@ -567,22 +437,6 @@ function computeInheritedValue( {
567437
blockStyles,
568438
} )
569439
)
570-
: null,
571-
variation && element
572-
? createContribution(
573-
pickLayerRootContribution(
574-
getStateSlice(
575-
getElementObject( variation, element ),
576-
selectedState
577-
)
578-
),
579-
createSourceDescriptor( 'blockVariationElement', {
580-
blockName,
581-
variation: ownVariation,
582-
blockStyles,
583-
element,
584-
} )
585-
)
586440
: null
587441
);
588442
}
@@ -611,7 +465,7 @@ function computeInheritedValue( {
611465

612466
/**
613467
* Shared memo for `buildInheritedValue`, keyed by Global
614-
* Styles object identity and a `(blockName, element, ownVariation)` composite.
468+
* Styles object identity and a `(blockName, ownVariation)` composite.
615469
*
616470
* @type {WeakMap<object, Map<string, Object>>}
617471
*/
@@ -646,8 +500,6 @@ export function buildInheritedValue( args ) {
646500
const key =
647501
( args.blockName || '' ) +
648502
'\u0001' +
649-
( args.element || '' ) +
650-
'\u0001' +
651503
( args.ownVariation || '' ) +
652504
'\u0001' +
653505
blockStylesKey +
@@ -667,6 +519,5 @@ export const __unstable = {
667519
isExplicitEmpty,
668520
isRefObject,
669521
pickLayerRootContribution,
670-
pickLayerElementContribution,
671522
deepMergeDroppingEmpties,
672523
};

packages/block-editor/src/components/global-styles/dimensions-panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function hasValue( value ) {
170170
* only — they are not CSS-inherited cascade properties, so descendant block
171171
* panels should not surface them as "inherited" placeholders.
172172
*/
173-
const NON_CASCADING_ROOT_LAYERS = new Set( [ 'root', 'rootElement' ] );
173+
const NON_CASCADING_ROOT_LAYERS = new Set( [ 'root' ] );
174174

175175
function isRootSourced( sources, pathKey ) {
176176
return NON_CASCADING_ROOT_LAYERS.has( sources?.[ pathKey ]?.layer );

packages/block-editor/src/components/global-styles/inherited-value-context.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,41 +99,36 @@ export function InheritedValueProvider( {
9999

100100
/**
101101
* Hook: returns the merged `inheritedValue` payload and source map for a
102-
* panel. Call once per panel, passing the element tag (if any) the panel
103-
* folds.
102+
* panel. Call once per panel.
104103
*
105104
* Before the Provider is mounted, or during hydration before the
106105
* `globalStylesDataKey` payload settles, the hook returns empty value and
107106
* source objects. Each panel's existing `inheritedValue = value` default
108107
* then keeps pre-feature behavior after bridge components pass `.value`.
109108
*
110109
* The returned object identity is stable across renders when none of
111-
* `(globalStyles, blockName, element, ownVariation)` have changed.
110+
* `(globalStyles, blockName, ownVariation)` have changed.
112111
*
113-
* @param {Object} [args]
114-
* @param {?string} [args.element] Element tag to fold (e.g. `h2`, `link`).
115112
* @return {{ value: Object, sources: Object }} Merged panel-scoped payload and source map.
116113
*/
117-
export function useInheritedValue( { element = null } = {} ) {
114+
export function useInheritedValue() {
118115
const ctx = useContext( InheritedValueContext );
119116
return useMemo( () => {
120117
if ( ! ctx || ! ctx.blockName ) {
121118
return { value: {}, sources: {} };
122119
}
123120
return buildInheritedValue( {
124121
blockName: ctx.blockName,
125-
element,
126122
ownVariation: ctx.ownVariation,
127123
globalStyles: ctx.globalStyles,
128124
blockStyles: ctx.blockStyles,
129125
selectedState: ctx.selectedState,
130126
} );
131-
}, [ ctx, element ] );
127+
}, [ ctx ] );
132128
}
133129

134130
export function useInheritedStyleValue( {
135131
blockName,
136-
element = null,
137132
ownVariation = null,
138133
selectedState = null,
139134
} ) {
@@ -145,20 +140,12 @@ export function useInheritedStyleValue( {
145140
}
146141
return buildInheritedValue( {
147142
blockName,
148-
element,
149143
ownVariation,
150144
globalStyles,
151145
blockStyles,
152146
selectedState,
153147
} );
154-
}, [
155-
blockName,
156-
element,
157-
ownVariation,
158-
globalStyles,
159-
blockStyles,
160-
selectedState,
161-
] );
148+
}, [ blockName, ownVariation, globalStyles, blockStyles, selectedState ] );
162149
}
163150

164151
/**

0 commit comments

Comments
 (0)