Problem/Motivation
Currently, the AI SEO module generates its report using the HTML rendered from the node revision view (/node/{nid}/revisions/{vid}/view) via a sub-request. This produces HTML that differs from what anonymous users actually see on the canonical URL, because:
- The revision view bypasses certain access checks and rendering contexts applied to the canonical route
- Block visibility, cache contexts, and anonymous-specific rendering logic may differ
- Metatags, schema markup, and other SEO-relevant head elements may not match the public-facing output
This means the SEO analysis is performed against HTML that does not accurately represent the page as seen by search engine crawlers.
Steps to reproduce
- Create or edit a node with published content
- Trigger an AI SEO report generation for that node
- Compare the HTML used for the report (revision view) with the HTML at the canonical URL rendered for anonymous users
- Observe differences in metatags, schema markup, block output, and rendered body content
Proposed resolution
Replace the revision-based sub-request with a render using the node canonical route (/node/{nid}) rendered as an anonymous user. This can be achieved by:
- Using
RenderEntityHtmlServicewith the canonical route and an anonymous account context instead of the revision route - Switching the account to anonymous via
AccountSwitcherInterfacebefore rendering and restoring it after - Building the sub-request against
/node/{nid}so all route-specific rendering, block visibility, and cache contexts match the public-facing output
Remaining tasks
- Update
RenderEntityHtmlServiceto build the sub-request against the canonical node URL instead of the revision URL - Inject
AccountSwitcherInterfaceinto the service and wrap the render call in an anonymous account context - Verify that the rendered HTML matches the anonymous public output including metatags and schema markup
- Add test coverage for the canonical render path
- Test against nodes with access-restricted revisions to confirm no privilege escalation
User interface changes
None. The SEO report UI remains unchanged. The improvement is internal to how the HTML is sourced.
API changes
RenderEntityHtmlServicemethod signature may be updated to accept a route name or render mode parameter- Any callers of the revision-based render method will need to be updated to use the new canonical render method
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | fix-revision-page-title.patch | 3.3 KB | r-mo |
Issue fork ai_seo-3616408
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
r-mo commentedThis patch and commit on 3616408-html-used-in-seo-reports addresses canonical rendering context, missing H1/HTML titles and Metatag cache leakage. It also includes the prerequisite route-service fix from [#3610576, MR !15](https://www.drupal.org/project/ai_seo/issues/3610576).
Remaining work for this issue:
**AI assistance disclosure:** The rendering changes and this comment were prepared with OpenAI Codex assistance. The prerequisite route-service changes come from MR !15 on #3610576.
Comment #4
r-mo commentedComment #6
j-vee commentedFixed in 1.1.4, thanks everyone!