fix(seo): wrap home page JSON-LD in @graph to add top-level @context#20
Conversation
The home page injected its JSON-LD as a bare top-level array (`[organizationJsonLd, productJsonLd, faqJsonLd]`). Each object carried its own `@context`, but the array itself had none, so consumers that treat the parsed JSON-LD as a single object read `r["@context"]` → `undefined` and crashed calling `.toLowerCase()` on it. Error tracking captured an unhandled `TypeError: undefined is not an object (evaluating 'r["@context"].toLowerCase')` from an injected structured-data reader on amend.sh. Wrap the three entities in a single `@graph` with one top-level `@context` and drop the now-redundant per-object `@context`. This fixes the crash trigger and produces a more standard structured-data shape. Resolves PostHog inbox report 019ec185-73e0-7f4a-a0cf-26b2dfa5d321. Generated-By: PostHog Code Task-Id: 38c8d80f-f631-448e-a9d6-88d20c7dd846
Greptile SummaryThis PR fixes a crash on the home page caused by a browser extension or structured-data reader calling
Confidence Score: 4/5The fix is correct and directly addresses the crash. The only concern is that the three exported JSON-LD objects no longer carry their own @context, making them silently invalid if imported in a new route without @graph wrapping. The core change — wrapping the entities in a @graph document — is the right approach and matches the JSON-LD spec. The export-level removal of @context from each object is technically sound today but leaves a maintenance trap: any new page that imports one of these objects and injects it directly will produce malformed structured data with no compile-time warning. apps/web/src/lib/seo.ts — the exported JSON-LD objects now lack @context and rely on callers always wrapping them in @graph Important Files Changed
Sequence DiagramsequenceDiagram
participant index.tsx
participant seo.ts
participant Browser
participant Reader as StructuredDataReader
index.tsx->>seo.ts: import organizationJsonLd, productJsonLd, faqJsonLd
index.tsx->>Browser: render script tag with JSON-LD
note over Browser,Reader: Before fix - bare array, no top-level @context
Browser->>Reader: parse JSON array
Reader-->>Browser: "TypeError on r["@context"].toLowerCase()"
note over Browser,Reader: After fix - @graph document with @context
Browser->>Reader: "parse @graph document"
Reader->>Reader: "r["@context"] = "https://schema.org""
Reader-->>Browser: structured data processed OK
|
Summary
Visitors hit an unhandled
TypeError: undefined is not an object (evaluating 'r["@context"].toLowerCase')on the amend.sh home page (captured by error tracking on 2026-06-06, Safari 26.3 / macOS).Root cause:
apps/web/src/routes/index.tsxinjected the page's JSON-LD as a bare top-level array:Each object carried its own
@context, but the array itself had none. Any consumer that treats the parsed JSON-LD as a single object readsr["@context"]→undefinedand crashes calling.toLowerCase()on it. The crashing code is third-party/injected (a browser extension or structured-data reader), so it can't be edited directly — but the array shape is what triggers it.Fix
Give the JSON-LD a single top-level
@contextby wrapping the three entities in a@graph, and drop the now-redundant per-object@contextinseo.ts:This fixes the crash trigger and produces a more standard structured-data shape.
Notes
organizationJsonLd,productJsonLd, andfaqJsonLdare only consumed inindex.tsx, so removing their per-object@contextis safe.check-typesin this environment (pnpm catalog/install error unrelated to this change), but the edits are mechanical and valid TypeScript.Resolves PostHog inbox report 019ec185-73e0-7f4a-a0cf-26b2dfa5d321.
🤖 Generated with Claude Code