Skip to content

rules(content): article-toc does not read JSON-LD nested in @graph, so a Yoast-style ItemList reports as missing #339

Closed

Description

@nc9

Found while fixing #317, which covered the seven schema/* rules with the same defect. content/article-toc has it too and was outside that issue's stated scope, so it was left alone rather than folded into #338.

checkTocSchema in packages/rules/src/content/article-toc.ts:118 reads each JSON-LD script and then does:

const data = JSON.parse(script.textContent || "");
const schemas: ItemListSchema[] = Array.isArray(data) ? data : [data];

So the only nodes it ever sees are the top level of each script. On a site whose JSON-LD is one {"@context":…,"@graph":[…]} wrapper, which is what Yoast, Rank Math and Slim SEO all emit and therefore most of the WordPress web, the wrapper is the only node and it has no @type. An ItemList describing the page's table of contents is nested inside and is never found.

The consequence is narrower than the seven rules in #317, because this is one input to a heuristic rather than the finding itself: the rule concludes the page has no TOC schema and reports accordingly. Still a false negative on correct markup.

The fix is the same one-line change that closed #317. flattenJsonLdNodes is exported from @squirrelscan/utils and already used by schema/local-business, the entity-map builder and, since #338, the seven schema rules:

const schemas = flattenJsonLdNodes(script.textContent || "");

Per script rather than over the joined schema.raw, because that join can mis-split a pretty-printed block (#1099). The helper returns an empty list for unparseable input, so the surrounding try/catch goes with it. Note that #338 also gave the helper a depth cap, so this is safe against a hostile @graph chain.

Acceptance Criteria

  • content/article-toc finds an ItemList nested in an @graph wrapper
  • The rule produces the same verdict from @graph markup as from the equivalent flat markup
  • A test proves it, and fails against the current implementation
  • Unparseable JSON-LD is still skipped rather than thrown on
  • A repo-wide check confirms no other rule still does Array.isArray(data) ? data : [data] on a parsed JSON-LD script

Activity

  1. added
    bug
    rules
    P3
    size: XS
    on Sep 23, 2026
  2. added 2 commits that reference this issue on Oct 9, 2026
  3. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugrulessize: XS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions