Skip to content

fix(audit): read a JSON-LD @graph's nodes in the wrapper's @context - #1681

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/audit-json-ld-graph-context
Oct 28, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/audit-json-ld-graph-context

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up B (second half) from #1565's round 37: Site Audit reads a JSON-LD @graph's nodes in the wrapper's @context.

jsonLd() flattened a @graph into its nodes without the wrapper's @context. So a page whose JSON-LD is one @graph with the context on the wrapper alone, as WordPress SEO plugins write it, failed json-ld-validity even though it's valid: no node "declared" schema.org. This also happens on main. The Action Center's structured data check uses the same evaluator, so such a task never closed by itself.

  • A @graph node now takes the wrapper's @context when it has none of its own, as JSON-LD reads it.
  • A node's own context is kept, whether it's a string, an array or an object.
  • A @graph with no context anywhere still fails.
  • The new structure.test.js fails on main.

⚠️ Scores change: on WordPress-style @graph sites, the next audit passes json-ld-validity, so the score goes up. Saved audits stay as they are until re-audited; no re-audit is needed. Open Action Center tasks raised by json-ld-validity on those pages close at their next check ("Checked automatically and done").

Merge together with #1680 (the sawFailing gate), in one deploy. See that PR for why.

Related issue

Follow-up from #1565 (round 37, item B).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

cd server && npx vitest run src/lib/audit/signals/structure.test.js

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Full checks were run in one tree with this batch's eight follow-up branches merged (after the review fixes):

  • server format, lint and npm test (no SUPABASE_* env, as in CI): 249 files, 3,365 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (445 files, 4,353 tests) and build: all pass.

Browser check (local, 1024 px): Prompts › Topics › Add Topic stops at 100 characters; the Action Center drawer opens without errors, and Check now doesn't show on tasks the API doesn't check.

A pre-push review was run on all eight branches of this batch, and its before-merge findings are fixed.

🤖 Generated with Claude Code

Follow-up B (second half) from ansvisor#1565's round 37. jsonLd() flattened a
@graph into its nodes without the wrapper's @context, so a page whose
JSON-LD is one @graph with the context on the wrapper alone (as
WordPress's SEO plugins write it) failed json-ld-validity though it's
valid: no node "declares" schema.org. That's on main too, and since the
Action Center's structured data check uses the same evaluator, such a
task never closed by itself.

A @graph's node now takes the wrapper's @context when it has none of its
own, as JSON-LD reads it; a node's own context is kept, and a @graph with
no context anywhere still fails. The new structure.test.js fails on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A @graph's nodes now carry their wrapper's context, so the same context
was turned into a string once per node. Keep each context's answer in a
Map keyed by the value, and test a large shared context with thousands
of nodes.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with 14acf8f: each @context is read once (a Map), with a test that bounds the time on a large shared context, and main merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants