Table Of Contents: Include headings exclusively within the core/post-content
block
#69366
+22
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Closes #69359
This PR updates the logic to ensure the
Table of Contents
block only considersHeading
elements within thecore/post-content
block. Previously, it included all headings on the page, including those in theHeader
andFooter
, which could lead to unintended results.Why?
Including
Heading
elements from outside thecore/post-content
block—such as those in theHeader
andFooter
—in theTable of Contents
block is not ideal, as it should strictly focus on the main content. The block should serve its intended purpose of summarizing the structure of the post by tabulating only theHeading
tags used within the post content.How?
The previous implementation used
getClientIdsWithDescendants
to get the client IDs of all the blocks in the editor. When theShow Template
mode is toggled (template-locked
editing mode ), this selector literally returns all the blocks within the editor. That includes theHeader
,Footer
, and the blocks within theTemplate
. This behavior causes the bug mentioned above.The current PR updates the usage to use
getBlockOrder
, which uses a recursive approach to exclusively get the nested blocks within thepost-content
using itsClient ID
. If theClient ID
becomes undefined for some reason ( e.g. when editing mode is set to post-only ), in such a scenario,getBlockOrder
gracefully falls back to return thetop-level
blocks.Testing Instructions
Heading
elements to theHeader
,Footer
, or within theTemplate
.Heading
elements inside the post content.Header
,Footer
, orTemplate
.Screenshots
Testing edge cases
