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

  1. Create or edit a node with published content
  2. Trigger an AI SEO report generation for that node
  3. Compare the HTML used for the report (revision view) with the HTML at the canonical URL rendered for anonymous users
  4. 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 RenderEntityHtmlService with the canonical route and an anonymous account context instead of the revision route
  • Switching the account to anonymous via AccountSwitcherInterface before 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 RenderEntityHtmlService to build the sub-request against the canonical node URL instead of the revision URL
  • Inject AccountSwitcherInterface into 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

  • RenderEntityHtmlService method 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.

CommentFileSizeAuthor
#3 fix-revision-page-title.patch3.3 KBr-mo

Issue fork ai_seo-3616408

Command icon 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

punamshelke created an issue. See original summary.

r-mo made their first commit to this issue’s fork.

r-mo’s picture

StatusFileSize
new3.3 KB

This 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:

  • Published content versus revisions: The selected revision is still rendered. For drafts or historical revisions, this intentionally differs from the currently published page. Published-page SEO analysis and draft/revision analysis need to be distinguished.
  • Access checks: Canonical route context does not execute normal route access checks. Explicit entity/revision access checks and tests covering restricted revisions are still needed.
  • Anonymous rendering: The patch retains the existing anonymous-rendering option rather than enforcing it for every analysis.
  • Public HTML equivalence: Broader verification is needed for block visibility, cache contexts, translations and schema markup. The existing breadcrumb-schema filtering remains unchanged.
  • Automated coverage: Regression tests still need adding. Local checks passed for two nodes using both canonical and revision analysis, including checks that metadata cached by the surrounding page is restored afterward.

**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.

r-mo’s picture

Status: Active » Needs work

  • j-vee committed 32d58e23 on 1.x authored by r-mo
    fix: #3616408 HTML used in to SEO reports generation
    
    Render the...
j-vee’s picture

Status: Needs work » Fixed

Fixed in 1.1.4, thanks everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • j-vee committed e619b80f on 1.x
    fix: Run queued analyses as the user who queued them
    
    Cron runs...