You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a REST endpoint exposing the Table of Contents heading resolver class #80786
Add a REST endpoint that exposes the heading resolver class (#80781), so the editor can retrieve headings for a post the same way the front end does.
Why
The front end resolves headings through the heading resolver class on the server. The editor currently has no way to call that same class, so it has to keep its own separate logic for working out headings from the block list. That's exactly the kind of duplication the heading resolver class exists to remove, and it's why the editor and the front end can currently disagree about what a table of contents should show.
A REST endpoint gives the editor a way to ask the server the same question the front end asks, using the same code, without needing to reimplement heading discovery in JavaScript.
How
⚠️ Depends on the results of #80794, which is testing whether reusing the existing server-side render mechanism (useServerSideRender) can meet the editor's needs without a dedicated endpoint. If that approach proves viable, this issue may be scaled back or dropped in favour of it.
Tasks:
Add a REST endpoint that accepts enough information to resolve headings for a given post (or, eventually, unsaved editor content) and calls the heading resolver class.
Keep the endpoint's response shape focused on what the editor needs to render a preview, rather than exposing internal resolver details.
Consider whether the endpoint needs to support resolving headings from a supplied block list, not just a saved post, to support live editor previews before saving.
Why not use the existing SSR method for blocks (useServerSideRender)? The editor can pass post_id, and then the existing front-end code should handle everything.
Adding a separate REST endpoint for every new and complex block won't be sustainable long term.
If the post ID isn't available in a certain editor context, then it's better to display a placeholder state. I think the Breadcrumbs block does something similar.
I wouldn't necessarily, but let's set that aside for a second.
I think the best approach is that we test the simplest option first. We can do a quick spike PoC using SSR as soon as the Headings Utility class PR is merged. If it works and the UX is ok then there's no need to over engineer this at all 🙏
To be clearer about the plan I'm proposing if we decide to go down this route (the one in this Issue):
The editor serializes its current block content and sends it, along with relevant post/template context and ToC settings.
PHP runs the same heading resolver used by front-end rendering, against that supplied content rather than loading post_content from the database. Obviously the resolver class ultimately operates on the same underlying data structures so whether they come from post_content (via a post ID) or directly as blocks doesn't matter.
The endpoint returns either resolved heading data for an editor preview, (or possibly even the rendered ToC HTML itself if exact server markup is the goal).
The editor debounces requests while the author types and retains the last successful preview during loading.
That gives us all three desirable behaviours:
New unsaved post: headings can render without a post ID.
Saved post with unsaved edits: preview updates from the editor’s current content, not the old draft.
Template shown against a post: resolver uses that post’s effective content/context.
I appreciate this is a bit more complex than the simpler SSR approach but it might (subject to discovery in #80794) prove necessary to achieve a solid UX.
From desired behaviors, what do we think is missing currently? The number #3 - "Template shown against a post: resolver uses that post’s effective content/context."?
I just did a quick test:
Add ToC to the Single Posts template
Open a post with headings
Enable "Show Template"
ToC block displays headings.
Mostly trying to figure out if we really need a special endpoint or SSR just to display the ToC preview in the editor.
Activity
Mamaduka commentedon Jul 28, 2026
Why not use the existing SSR method for blocks (
useServerSideRender)? The editor can passpost_id,and then the existing front-end code should handle everything.Adding a separate REST endpoint for every new and complex block won't be sustainable long term.
getdave commentedon Jul 28, 2026
It's related to the situation @t-hamano raised where sometimes we won't yet have a Post ID
#42229 (comment)
Mamaduka commentedon Jul 28, 2026
The endpoint will also need Post ID, no?
If the post ID isn't available in a certain editor context, then it's better to display a placeholder state. I think the Breadcrumbs block does something similar.
getdave commentedon Jul 28, 2026
I wouldn't necessarily, but let's set that aside for a second.
I think the best approach is that we test the simplest option first. We can do a quick spike PoC using SSR as soon as the Headings Utility class PR is merged. If it works and the UX is ok then there's no need to over engineer this at all 🙏
I'll rework the plan in the main Issue.
getdave commentedon Jul 29, 2026
To be clearer about the plan I'm proposing if we decide to go down this route (the one in this Issue):
post_content(via a post ID) or directly as blocks doesn't matter.That gives us all three desirable behaviours:
I appreciate this is a bit more complex than the simpler SSR approach but it might (subject to discovery in #80794) prove necessary to achieve a solid UX.
Mamaduka commentedon Jul 29, 2026
Also left a comment on the PR - #80796 (comment).
From desired behaviors, what do we think is missing currently? The number
#3- "Template shown against a post: resolver uses that post’s effective content/context."?I just did a quick test:
Mostly trying to figure out if we really need a special endpoint or SSR just to display the ToC preview in the editor.