Skip to content

Commit 9bdccb9

Browse files
committed
fix: Ensure FAQ heading synchronization reacts to inner block changes
Updates the `useSyncQuestionHeadingLevels` hook to explicitly select the inner FAQ question blocks using `useSelect`. By including these blocks in the `useEffect` dependencies, heading levels are now correctly re-synchronized when questions are added, removed, or reordered within the FAQ block.
1 parent d4eab60 commit 9bdccb9

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/faq/edit.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ function syncQuestionHeadingLevels(
7373
}
7474

7575
function useSyncQuestionHeadingLevels( clientId, headingLevel, isAccordion ) {
76+
const questionBlocks = useSelect(
77+
( select ) => {
78+
const { getBlocksByClientId } = select( blockEditorStore );
79+
const [ faqBlock ] = getBlocksByClientId( clientId );
80+
81+
return collectQuestionBlocks( faqBlock?.innerBlocks || [] );
82+
},
83+
[ clientId ]
84+
);
7685
const { getBlocksByClientId } = useSelect(
7786
( select ) => select( blockEditorStore ),
7887
[]
@@ -88,6 +97,7 @@ function useSyncQuestionHeadingLevels( clientId, headingLevel, isAccordion ) {
8897
clientId,
8998
headingLevel,
9099
isAccordion,
100+
questionBlocks,
91101
getBlocksByClientId,
92102
updateBlockAttributes,
93103
] );

0 commit comments

Comments
 (0)