Skip to content

fix(html-analyzer): sort JSON-LD keys to suppress false prerender diffs (LLMO-4462)#1558

Open
anagarwa wants to merge 1 commit intomainfrom
feat/llmo-4462-jsonld-key-sort
Open

fix(html-analyzer): sort JSON-LD keys to suppress false prerender diffs (LLMO-4462)#1558
anagarwa wants to merge 1 commit intomainfrom
feat/llmo-4462-jsonld-key-sort

Conversation

@anagarwa
Copy link
Copy Markdown
Contributor

Summary

  • Root cause: filterHtmlContent normalized JSON-LD with JSON.parse + JSON.stringify(obj, null, 2), which preserves insertion order. HDFC's server returns the same JSON-LD with different key orderings between the curl (original) and lambda (prerendered) fetches, so two semantically identical blocks produced different strings → false diff in the pre/post compare UI.
  • Fix: Added deepSortKeys() helper that recursively sorts all object keys alphabetically before serialization. Applied in both the browser (filterHtmlBrowser) and Node.js (filterHtmlNode) code paths.
  • Scope: Arrays are traversed but element order is preserved (JSON-LD @graph ordering can be meaningful).

Fixes LLMO-4462 — confirmed via Slack thread in #project-tokowaka-customers (2026-04-23) where the team manually verified pre/post JSON-LD was identical on HDFC FD Calculator and Investor Relations pages but showed as a diff.

Test plan

  • New unit test: two JSON-LD objects with identical data but different key orderings produce the same serialized ld-json code block
  • New unit test: nested object keys are sorted recursively
  • New unit test: array element order is preserved
  • All 76 existing tests pass

🤖 Generated with Claude Code

…s false diffs

Semantically identical JSON-LD blocks with different server-side key orderings
produced different serialized strings, causing the prerender pre/post compare UI
to flag them as material changes. Sorting keys recursively before JSON.stringify
ensures stable output regardless of key insertion order.

Fixes false JSON-LD diffs for HDFC (LLMO-4462) and any site where the curl
and lambda fetches return the same JSON-LD in different key order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant