Skip to content

Conversation

@benlife5
Copy link
Contributor

@benlife5 benlife5 commented Oct 28, 2025

Automatically add breadcrumbs and reviews schema to entity pages, if the data is present on the document.

Breadcrumbs and reviews get added as separate blocks. Wraps the whole schema in @graph.

@benlife5 benlife5 added the create-dev-release Triggers dev release workflow label Oct 28, 2025
@github-actions
Copy link
Contributor

Warning: Component files have been updated but no migrations have been added. See https://github.com/yext/visual-editor/blob/main/packages/visual-editor/src/components/migrations/README.md for more information.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 28, 2025

pages-visual-editor-starter

npm i https://pkg.pr.new/yext/visual-editor/@yext/visual-editor@843

commit: ff9c939

asanehisa
asanehisa previously approved these changes Oct 28, 2025
Copy link
Contributor

@asanehisa asanehisa left a comment

Choose a reason for hiding this comment

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

lgtm assuming testing in platform works out!

@benlife5 benlife5 marked this pull request as draft October 28, 2025 20:47
@benlife5 benlife5 marked this pull request as ready for review October 28, 2025 21:17
asanehisa
asanehisa previously approved these changes Oct 29, 2025
Copy link
Collaborator

@mkilpatrick mkilpatrick left a comment

Choose a reason for hiding this comment

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

What happens with schema editing? Do the reviews or breadcrumbs show up or does this get added post saving and only when applied to the page?

@benlife5 benlife5 marked this pull request as draft October 30, 2025 13:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

Centralizes directory-parent extraction by adding and exporting getDirectoryParents(streamDocument) in utils, removes duplicate local helpers from Breadcrumbs which now imports the shared helper, and extends getSchema to optionally emit a composite JSON-LD @graph containing the main resolved schema plus BreadcrumbList and AggregateRating blocks when applicable. getSchema's error handling was changed to return a graph with the default schema on failure. Tests for schema generation were expanded to cover directory hierarchies, breadcrumb resolution, and review-based rating blocks.

Sequence Diagram(s)

sequenceDiagram
    participant Breadcrumbs
    participant StreamDocument
    participant getDirectoryParents
    participant getSchema
    participant getBreadcrumbsSchema
    participant getAggregateRatingSchemaBlock
    participant Output as @graph

    Breadcrumbs->>StreamDocument: receive document
    Breadcrumbs->>getDirectoryParents: getDirectoryParents(streamDocument)
    getDirectoryParents-->>Breadcrumbs: [{slug,name}, ...]

    StreamDocument->>getSchema: getSchema(streamDocument)
    rect rgb(240,248,255)
      Note over getSchema: Resolve main entity schema
      getSchema->>getSchema: resolveMainSchema()
    end

    rect rgb(240,245,240)
      alt has directory parents
        getSchema->>getDirectoryParents: extract directory parents
        getDirectoryParents-->>getSchema: [{slug,name}, ...]
        getSchema->>getBreadcrumbsSchema: build BreadcrumbList
        getBreadcrumbsSchema-->>getSchema: BreadcrumbList schema
      end
    end

    rect rgb(245,240,240)
      alt has FIRSTPARTY reviews
        getSchema->>getAggregateRatingSchemaBlock: build rating block
        getAggregateRatingSchemaBlock-->>getSchema: AggregateRating schema
      end
    end

    rect rgb(250,250,240)
      Note over getSchema: Combine resolved pieces into @graph (filtering missing parts)
      getSchema-->>Output: { "@graph": [ main, breadcrumbs?, aggregateRating? ] }
    end
Loading

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "feat: add breadcrumbs and reviews schema" directly and accurately describes the main changes in the changeset. The title clearly corresponds to the substantial modifications across multiple files: the addition of breadcrumbs and reviews schema functionality to getSchema.ts, the export of getDirectoryParents utilities, comprehensive test coverage updates, and refactoring of Breadcrumbs.tsx to use the new shared utility. The title is concise, specific, and uses the conventional "feat:" prefix to indicate a feature addition. A teammate scanning the commit history would immediately understand that this PR adds breadcrumbs and reviews schema capabilities to entity pages.
Description Check ✅ Passed The pull request description is directly related to the changeset and provides meaningful context about the changes. The description accurately explains the new functionality: automatically adding breadcrumbs and reviews schema when data is present, organizing them as separate blocks, and wrapping the schema in an @graph container. These points align precisely with the modifications in getSchema.ts (new breadcrumbs and aggregate rating utilities), the test expansions (covering breadcrumb and review scenarios), and the overall schema restructuring visible in the file changes. The description is neither vague nor generic, as it conveys specific technical details about implementation approach.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch breadcrumbs-reviews-schema

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5373188 and ff9c939.

⛔ Files ignored due to path filters (3)
  • packages/visual-editor/src/components/testing/screenshots/BreadcrumbsSection/[tablet] default props with document data.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/BreadcrumbsSection/[tablet] version 4 props.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
  • packages/visual-editor/src/components/testing/screenshots/BreadcrumbsSection/[tablet] version 8 with non-default props with document data.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
📒 Files selected for processing (2)
  • packages/visual-editor/src/utils/getSchema.test.ts (4 hunks)
  • packages/visual-editor/src/utils/getSchema.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/visual-editor/src/utils/getSchema.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/visual-editor/src/utils/getSchema.test.ts (2)
packages/visual-editor/src/utils/getSchema.ts (1)
  • getSchema (14-60)
packages/visual-editor/src/utils/index.ts (1)
  • getSchema (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: call_unit_test / unit_tests (18.x)
  • GitHub Check: call_unit_test / unit_tests (20.x)
  • GitHub Check: semgrep/ci
  • GitHub Check: create-dev-release
🔇 Additional comments (4)
packages/visual-editor/src/utils/getSchema.test.ts (4)

5-38: LGTM! Clean test for basic schema resolution.

This test correctly verifies that a location with schemaMarkup and no directory/reviews produces a simple @graph with the resolved schema.


40-89: LGTM! Default schema fallback test is correct.

This test properly validates that when no schemaMarkup is provided, the system falls back to the default LocalBusiness schema with appropriate template placeholders.


267-360: LGTM! Directory city test is comprehensive.

This test correctly validates schema generation for a directory city page, including the proper CollectionPage schema and complete breadcrumb chain ending with the current page.


362-414: LGTM! Directory root test correctly handles edge case.

This test properly validates that the root directory page generates a schema with a single-entry breadcrumb list (just the root itself), which is the correct behavior when there are no parent directories.


Comment @coderabbitai help to get the list of available commands and usage tips.

mkilpatrick
mkilpatrick previously approved these changes Oct 30, 2025
@benlife5 benlife5 marked this pull request as ready for review October 30, 2025 19:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19562ae and 3dad86e.

⛔ Files ignored due to path filters (1)
  • packages/visual-editor/src/components/testing/screenshots/InsightSection/[desktop] version 7 props with entity values.png is excluded by !**/*.png, !packages/visual-editor/src/components/testing/screenshots/**
📒 Files selected for processing (4)
  • packages/visual-editor/src/components/pageSections/Breadcrumbs.tsx (1 hunks)
  • packages/visual-editor/src/utils/getSchema.test.ts (4 hunks)
  • packages/visual-editor/src/utils/getSchema.ts (2 hunks)
  • packages/visual-editor/src/utils/index.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/visual-editor/src/utils/getSchema.test.ts (1)
packages/visual-editor/src/utils/getSchema.ts (1)
  • getSchema (14-60)
packages/visual-editor/src/utils/getSchema.ts (2)
packages/visual-editor/src/utils/resolveYextEntityField.ts (1)
  • resolveSchemaJson (230-240)
packages/visual-editor/src/utils/applyTheme.ts (1)
  • StreamDocument (19-37)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: call_unit_test / unit_tests (18.x)
  • GitHub Check: call_unit_test / unit_tests (20.x)
  • GitHub Check: semgrep/ci

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/visual-editor/src/utils/getSchema.ts (2)

46-52: Consider removing unnecessary spread operators.

The spread operators on lines 49-50 are redundant since breadcrumbsSchema and aggregateRatingSchemaBlock are already objects. You can simplify this to:

 return {
   "@graph": [
     resolvedSchemaMarkup,
-    breadcrumbsSchema && { ...breadcrumbsSchema },
-    aggregateRatingSchemaBlock && { ...aggregateRatingSchemaBlock },
+    breadcrumbsSchema,
+    aggregateRatingSchemaBlock,
   ].filter(Boolean),
 };

91-107: Consider enhancing the TSDoc to clarify behavior.

The function correctly extracts directory parents, but the documentation could clarify that it returns the first matching dm_directoryParents_* key found. While this is likely the expected behavior (typically only one such key should exist), making it explicit would improve clarity:

 /**
  * getDirectoryParents returns an array of objects. If no dm_directoryParents or children of
- * the directory parent are not the expected objects, returns an empty array.
+ * the directory parent are not the expected objects, returns an empty array.
+ * If multiple dm_directoryParents_* keys exist, returns the first valid match.
  */
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dad86e and 5373188.

📒 Files selected for processing (2)
  • packages/visual-editor/src/utils/getSchema.test.ts (4 hunks)
  • packages/visual-editor/src/utils/getSchema.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/visual-editor/src/utils/getSchema.test.ts (2)
packages/visual-editor/src/utils/getSchema.ts (1)
  • getSchema (14-60)
packages/visual-editor/src/utils/index.ts (1)
  • getSchema (12-12)
packages/visual-editor/src/utils/getSchema.ts (2)
packages/visual-editor/src/utils/resolveYextEntityField.ts (1)
  • resolveSchemaJson (230-240)
packages/visual-editor/src/utils/applyTheme.ts (1)
  • StreamDocument (19-37)
🔇 Additional comments (9)
packages/visual-editor/src/utils/getSchema.test.ts (5)

5-38: LGTM! Test correctly validates schema without breadcrumbs or reviews.

The test properly verifies that a location without directory parents or reviews produces a simple @graph with just the resolved schema markup.


40-89: LGTM! Comprehensive test of default schema generation.

This test properly validates the fallback behavior when no custom schemaMarkup is provided, ensuring the default LocalBusiness schema is generated with field placeholders.


91-265: LGTM! Comprehensive test validates full @graph composition.

This test properly verifies:

  • Main schema resolution
  • BreadcrumbList with all directory parents plus the current page (positions 1-5)
  • AggregateRating block from FIRSTPARTY reviews

The test addresses previous concerns about including the current page in breadcrumbs (line 247) and correctly expects string values for ratings (lines 257-258).


267-360: LGTM! Test correctly validates directory page schema generation.

This test properly verifies that directory entities generate:

  • CollectionPage schema with ItemList mainEntity
  • BreadcrumbList including the current directory page
  • No AggregateRating block (as expected for directory pages)

362-399: LGTM! Test correctly validates root directory edge case.

This test properly verifies that the directory root generates only the main CollectionPage schema without breadcrumbs, which is correct since root pages have no directory parents.

packages/visual-editor/src/utils/getSchema.ts (4)

75-89: LGTM! Validation logic is sound.

The helper correctly validates that directory parents have the expected structure with name and slug string properties.


109-145: LGTM! Breadcrumb schema generation is correct.

This function properly:

  • Extracts directory parents using the shared helper
  • Maps parents to ListItems with correct position numbering
  • Includes the current page as the final breadcrumb item (lines 128-138), addressing the previous review concern
  • Uses appropriate @id values (relativePrefixToRoot for parents, pageId for current page)

147-187: LGTM! Aggregate rating schema generation is correct.

This function properly:

  • Validates that ref_reviewsAgg exists and is an array
  • Searches for FIRSTPARTY publisher reviews
  • Checks that both averageRating and reviewCount are defined before use
  • Converts values to strings (lines 177-178), which is acceptable per Schema.org specification and was confirmed in previous review discussions
  • Returns early when FIRSTPARTY is found (efficient, as only one should exist)

14-60: LGTM! Schema generation orchestration is well-structured.

The main function properly:

  • Resolves the document path for schema resolution
  • Conditionally builds a composite @graph for non-locator entities with main schema, breadcrumbs, and ratings
  • Filters out undefined blocks with filter(Boolean)
  • Falls back to a single-item @graph for locator pages or when conditions aren't met
  • Handles errors gracefully by returning a valid @graph with the default schema

The implementation correctly addresses all previous review concerns.

@benlife5 benlife5 merged commit eb209b5 into main Oct 30, 2025
16 checks passed
@benlife5 benlife5 deleted the breadcrumbs-reviews-schema branch October 30, 2025 20:53
mkouzel-yext pushed a commit that referenced this pull request Oct 30, 2025
Automatically add breadcrumbs and reviews schema to entity pages, if the
data is present on the document.

Breadcrumbs and reviews get added as separate blocks. Wraps the whole
schema in `@graph`.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-dev-release Triggers dev release workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants