Skip to content

23181 fix product properties in schema aggregator output#23185

Open
pls78 wants to merge 2 commits intotrunkfrom
23181-fix-product-properties-in-schema-aggregator-output
Open

23181 fix product properties in schema aggregator output#23185
pls78 wants to merge 2 commits intotrunkfrom
23181-fix-product-properties-in-schema-aggregator-output

Conversation

@pls78
Copy link
Copy Markdown
Member

@pls78 pls78 commented Apr 21, 2026

Context

  • The products that are rendered in the schemamap have incorrect @id values for mainEntityOfPage and image properties.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug in Schema aggregator where products Schema pieces had incorrect @id values for mainEntityOfPage and image properties.

Relevant technical choices:

  • The root cause is that Meta_Tags_Context_Memoizer::for_current_page() caches the first call's result. WPSEO_WooCommerce_Schema relies on for_current_page() for canonical/main_schema_id (per-product values), so every product after the first reuses the first product's URL
  • A new method has then been introduced in the Meta_Tags_Context_Memoizer that allows to "swap" the current page, allowing to fetch data for each product.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Make sure you have WooCoomerce and Yoast WooCommerce SEO installed and activated
  • Go to Yoast SEO -> Settings -> Site features and turn on Schema aggregation endpoint
  • Create at least two different products
  • Visit YOUR-BLOG-URL/wp-json/yoast/v1/schema-aggregator/get-schema/product
    • Copy the output
    • Paste it in https://schema-visualizer.yoast.com/
      • Use the validator to validate it
      • By using the visualization tool make sure that each Product piece is connected to its own Image, which is the same one referenced by the WebPage as mainEntityOfPage`

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • N/A

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.
  • This PR also affects Yoast SEO for Google Docs. I have added a changelog entry starting with [yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached the Google Docs Add-on label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.
  • I have run grunt build:images and commited the results, if my PR introduces new images or SVGs.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #23181

pls78 added 2 commits April 21, 2026 15:27
…oizer

Callers iterating over indexables (notably the schema aggregator) need to
temporarily redirect what `for_current_page()` resolves to and then restore
the prior value. Expose this as an atomic save/restore helper instead of
letting callers peek into the memoizer's internal cache.
…external schema

When aggregating schema for multiple WooCommerce products, the `image` and
`mainEntityOfPage` `@id`s on every `Product` piece were identical. Root
cause: `WPSEO_WooCommerce_Schema` derives those `@id`s from
`YoastSEO()->meta->for_current_page()`, which the memoizer resolves once
per request — so the first product's canonical wins for all subsequent
products.

Prime the memoizer's current_page cache with each indexable's context
around the external `collect()` call, and restore the previous value via
`try/finally` (so a throwing integration can't leak the override). This
fixes every per-product field generated by `WPSEO_WooCommerce_Schema`
(image, mainEntityOfPage, variation images, BuyAction target), not just
the two originally reported.
@pls78 pls78 added the changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog label Apr 21, 2026
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 5

Warning

No base build found for commit 8124863 on trunk.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 49.913%

Details

  • Patch coverage: 9 of 9 lines across 2 files are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 38691
Covered Lines: 19312
Line Coverage: 49.91%
Coverage Strength: 4.04 hits per line

💛 - Coveralls

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

Labels

changelog: bugfix Needs to be included in the 'Bugfixes' category in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema aggregator: products have incorrect data due to memoization

2 participants