Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ntsekouras opened this issue Sep 12, 2023 · 9 comments
Labels
[Block] Table of contents (experimental) Affects the Table of contents Block [Package] Block library /packages/block-library [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Bug An existing feature does not function as intended

Comments

@ntsekouras
Copy link
Contributor

ntsekouras commented Sep 12, 2023

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

@ntsekouras ntsekouras added [Type] Bug An existing feature does not function as intended [Package] Block library /packages/block-library [Block] Table of contents (experimental) Affects the Table of contents Block labels Sep 12, 2023
@alexstine
Copy link
Contributor

FYI @Mamaduka is currently working on some enhancements for the block. Not sure if this is included or not.

@Mamaduka
Copy link
Member

Yes, this is on my list.

@annezazu
Copy link
Contributor

Came here to report this too after I found it showed the Comments block heading:

table.of.contents.bug.mov

@annezazu annezazu changed the title Table of Contents in page renders the headings of a template too in site editor Table of Contents: prevent headings of template from rendering in list in Site Editor Sep 12, 2023
@Mamaduka
Copy link
Member

@ntsekouras, can you provide steps on how I can reproduce the error described here - #51477 (comment).

@ntsekouras
Copy link
Contributor Author

@ntsekouras, can you provide steps on how I can reproduce the error described here - #51477 (comment).

  • In a page add a heading and a TOC block.
  • View that page in site editor
  • Edit the template to add an extra heading block
  • In template inspector sidebar click on the template name and select swap template.

@Mamaduka
Copy link
Member

I just tested the above scenario with #54224. There's no error, and the editor doesn't crash when viewing template-swapping options.

I can still see extra headings from the templates.

@ntsekouras
Copy link
Contributor Author

Hope the video helps to reproduce.

Screen.Recording.2023-09-13.at.2.02.02.PM.mov

@Mamaduka
Copy link
Member

@ntsekouras, I meant that I can reproduce the error on trunk but not when testing with recent changes to Toc block #54224.

@mrfoxtalbot
Copy link

I can still reproduce this. If I add the TOC to the single post template....

Screenshot 2024-09-04 at 12 37 40

... it lists the headings footer's template, not in the post content:

Screenshot 2024-09-04 at 12 41 08

That said, fixing #41173 will also fix this issue so I will close this one.

@mrfoxtalbot mrfoxtalbot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Table of contents (experimental) Affects the Table of contents Block [Package] Block library /packages/block-library [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants