Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(schema-org): dedupe typed arrays by @type during node merge#702

Merged
harlan-zw merged 1 commit into
mainfrom
fix/schema-org-offer-merge-conflict
Mar 24, 2026
Merged

fix(schema-org): dedupe typed arrays by @type during node merge#702
harlan-zw merged 1 commit into
mainfrom
fix/schema-org-offer-merge-conflict

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

πŸ”— Linked issue

Resolves harlan-zw/nuxt-schema-org#94

❓ Type of change

  • πŸ“– Documentation
  • 🐞 Bug fix
  • πŸ‘Œ Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

πŸ“š Description

When two schema-org entries share the same @id (e.g. two Product nodes from different components), the merge() function deep-merged their nested objects. For arrays of typed schema objects like offers, this caused conflicting scalar values (e.g. availability: InStock vs OutOfStock) to both be retained instead of the later definition winning.

Extends the existing @type deduplication logic (previously only applied to potentialAction) to all arrays of typed schema objects. When merging arrays where every element has a @type property, later definitions now override earlier ones by type.

When two components define Product with different offers.availability
values, the merge function was concatenating the offers arrays instead
of letting the later definition win. Now arrays of typed schema.org
objects are deduped by @type, matching the existing potentialAction
behavior.

Closes harlan-zw/nuxt-schema-org#94
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Bundle Size Gzipped
Client (Minimal) 10.5 kB 4.3 kB
Server (Minimal) 10.2 kB 4.2 kB
Vue Client (Minimal) 11.4 kB 4.7 kB
Vue Server (Minimal) 11.1 kB 4.6 kB

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
πŸ“ Walkthrough

Walkthrough

This change fixes a merging conflict in schema.org object handling by implementing deduplication logic for arrays of typed objects. When merging multiple schema.org objects with the same @type, the system now uses the last-encountered definition, allowing later values to override earlier ones instead of combining conflicting properties.

Changes

Cohort / File(s) Summary
Array Merge Deduplication Logic
packages/schema-org/src/core/util.ts
Implements @type-based deduplication for typed schema.org arrays; builds a map from @type to the last encountered object, allowing later definitions to override earlier ones. Non-typed object arrays retain original merge behavior.
Test Coverage for Merge Conflicts
packages/schema-org/test/ssr/dupes.test.ts
Adds SSR test case validating that when two defineProduct nodes have matching name/image/price but conflicting offers.availability, the second product's OutOfStock value correctly prevails in the merged output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 When schemas clash with conflicting types,
Last one wins through deduplication's might!
No more confusion, conflicts take flight,
Merging typed objects is now done right! ✨

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly summarizes the main change: fixing schema-org merge logic by deduplicating typed arrays by @type during node merge.
Linked Issues check βœ… Passed The code changes fully address issue #94 by implementing deduplication of typed schema.org arrays by @type, ensuring later definitions override earlier ones and preventing stale availability values.
Out of Scope Changes check βœ… Passed All changes are scoped to fixing the merge conflict issue: core merge logic updates in util.ts and a focused test case in dupes.test.ts covering the specific availability conflict scenario.
Description check βœ… Passed The PR description fully addresses the template requirements with linked issue, appropriate type selection, and detailed explanation of the bug fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/schema-org-offer-merge-conflict

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

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

@harlan-zw harlan-zw merged commit b2caf01 into main Mar 24, 2026
6 checks passed
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.

Problem with merging

1 participant