Skip to content

Table of Contents: prevent headings of template from rendering in list in Site Editor #54385

@ntsekouras

Description

@ntsekouras

Description

If we have page that contains a Table of Contents block and we view this page in the site editor, the block also renders the other template headers. I'm not sure if this is something known and if is something wrong with how the headings are assigned to that block.

This might be serious enough because of the side effects of the block to update its attributes based on existing static markup and the discovery method it uses to find headings. In such a case if we render the template in a BlockPreview, it crashes the browser. It was discovered here. It seems that by using getClientIdsWithDescendants when we are in site editor has unexpected results.

Step-by-step reproduction instructions

  1. In a page add a heading and a TOC block.
  2. View that page in site editor
  3. Edit the template and add some more headers
  4. View the page again
  5. Observe that the TOC inside the Post Content block also renders the template's headings.

Screenshots, screen recording, code snippet

Screen.Recording.2023-09-12.at.5.19.49.PM.mov

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Table of contents (experimental)Affects the Table of contents Block[Package] Block library/packages/block-library[Status] DuplicateUsed to indicate that a current issue matches an existing one and can be closed[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions