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

Document outline does not detect headings in the content when template-lock is used #68820

Open
3 of 6 tasks
carolinan opened this issue Jan 22, 2025 · 12 comments
Open
3 of 6 tasks
Assignees
Labels
[Feature] Document Outline An option that outlines content based on a title and headings used in the post/page [Type] Bug An existing feature does not function as intended

Comments

@carolinan
Copy link
Contributor

carolinan commented Jan 22, 2025

Description

When you edit a post an enable the option "Show template", the document outline displays the heading levels correctly.
But when you create or edit a page, where the template is shown by default, the document outline incorrectly says that there are no headings in the content. Heading blocks in the template show.

This was reported in #68684 (comment) but I could not find a dedicated issue for it.
Please close this if it is a duplicate :)

Step-by-step reproduction instructions

With Gutenberg trunk active, create a new page.
In the content, add a heading.
Open the Document outline.
Confirm that it is empty.

Screenshots, screen recording, code snippet

No response

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

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@carolinan carolinan added [Feature] Document Outline An option that outlines content based on a title and headings used in the post/page [Type] Bug An existing feature does not function as intended labels Jan 22, 2025
@carolinan carolinan self-assigned this Jan 22, 2025
@SainathPoojary
Copy link
Contributor

Hi @carolinan,

I investigated the issue, and it seems to be related to the getBlocks function in Document Outline. While the post-content block has innerBlocks visible in the List View, it is returning an empty array in our case. This is why the Document Outline is unable to retrieve the heading blocks.

I also tried fetching innerBlocks using getBlocksByClientId, but even then, the post-content block returns empty innerBlocks.

@carolinan
Copy link
Contributor Author

Yes I found the same.

@singhakanshu00
Copy link

singhakanshu00 commented Jan 22, 2025

Hi @carolinan for the solution, I was thinking of fetching the blocks from useEntityBlockEditor from @wordpress/core-data instead of getBlocks from blockEditorStore, and by doing this I solved the issue. Let me know if this will be a correct approach.

And for this additionally we need to fetch currentPostId and currentPostType from editorStore at this line.

const { getEditedPostAttribute } = select( editorStore );

@carolinan
Copy link
Contributor Author

I am not familiar with useEntityBlockEditor .
If you have a PR, please submit it and then I will work on something else, and unassign myself.
I picked this up only because I was already working on another enhancement for the document outline.


There is another issue, and a decision needs to be made about what the expected workflow is.

If the template has a heading, it is showing in the document outline even though it is not showing in the List View.
Clicking on the item in the outline does not select the block. So it works differently than anywhere else. Perhaps the item should not be clickable since it can't be edited.

@carolinan
Copy link
Contributor Author

carolinan commented Jan 22, 2025

Perhaps the item should not be clickable since it can't be edited.

Coming back to this, my assumption is that we do want the headings that are in the template to show in this case, because of course they affect the heading level order and duplicate H1 count on the page.

@carolinan carolinan changed the title Document outline does not detect headings when template lock is used Document outline does not detect headings in the content when template-lock is used Jan 22, 2025
@singhakanshu00
Copy link

singhakanshu00 commented Jan 22, 2025

Coming back to this, my assumption is that we do want the headings that are in the template to show in this case, because of course they affect the heading level order and duplicate H1 count on the page.

Now, this will be a little tricky with the approach I mentioned, as useEntityBlockEditor fetches block from the post content, but the heading in the template is not part of the post content.

Video shows useEntityBlockEditor fetches block that are in the post content, here only the heading that included in the content "a heading"

Screen.Recording.2025-01-22.at.1.58.27.PM.mov

@carolinan
Copy link
Contributor Author

I did not understand what you wanted to show with the video, since it does not show the outline.

@carolinan
Copy link
Contributor Author

Is there a reason not to combine the blocks from the template (the current getblocks) and the post content? Why would only one be used?

@Mamaduka
Copy link
Member

I suggest we agree on the source of the heading blocks the Document Outline should display before proceeding to the solution.

@carolinan
Copy link
Contributor Author

carolinan commented Jan 22, 2025

I tested the post one more time and I was wrong. The pages and posts behave the same way.

When the template shows they both show the headings that are in the template.
When the template is not showing they both show the headings that are in the post content.

So there is no bug with displaying the items.
There is a bug where the item is a button and clicking on it does nothing when "show template" is enabled.
There is a possible enhancement that involves listing headings from both, when "show template" is enabled.

@rinkalpagdar
Copy link
Contributor

I think the document outline shows the correct headings, when "show template" is on it shows the headings of the template or else it will show the headings of the page content. Please correct me if I am wrong.

document-outline-headings.mp4

@carolinan
Copy link
Contributor Author

carolinan commented Jan 24, 2025

That is how it is working today, yes.

And my perspective is that it defeats the purpose of the outline.

  • The outline is not correct.
  • It is not obvious that it is showing different headings, as we saw from the first report.
  • The accessibility feature that presents the incorrect heading levels and duplicate H1's does not work since it does not show the result for the complete page that visitors see.
  • It is confusing that when the template is showing, I can add and edit headings in the content and the outline does not change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Document Outline An option that outlines content based on a title and headings used in the post/page [Type] Bug An existing feature does not function as intended
Projects
Development

No branches or pull requests

5 participants