Skip to content

fix(utils): ignore microdata inside <template> elements - #4400

Merged
janbuchar merged 1 commit into
apify:masterfrom
SwastikTripathi:fix/microdata-template
Nov 13, 2026
Merged

janbuchar merged 1 commit into
apify:masterfrom
SwastikTripathi:fix/microdata-template

Conversation

@SwastikTripathi

Copy link
Copy Markdown
Contributor

extractMicrodata returns items from inside <template> elements. In a browser that content is an inert fragment, not part of the document, so it has no microdata. Pages built with Alpine.js or Vue ship their list markup in <template x-for>, and the placeholders come back as real items:

<div itemscope itemtype="https://schema.org/ItemList">
  <template x-for="product in products">
    <div itemprop="itemListElement" itemscope itemtype="https://schema.org/Product">
      <span itemprop="name" x-text="product.name"></span>
    </div>
  </template>
  <div itemprop="itemListElement" itemscope itemtype="https://schema.org/Product">
    <span itemprop="name">Rendered</span>
  </div>
</div>
<template><div itemscope itemtype="https://schema.org/Offer"><span itemprop="price">{{ price }}</span></div></template>

Before, the list has two products (one with name: '') and there is a second top-level Offer with price: '{{ price }}'. After, only the rendered product.

cheerio keeps template content as ordinary children, the same cause as the htmlToText fix in #4399. The property walk no longer descends into <template>, and top-level items and itemref ids inside a template are skipped. The new test covers all three and fails before the change.

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 13, 2026
@janbuchar
janbuchar self-requested a review November 13, 2026 14:25
@janbuchar
janbuchar merged commit 7416673 into apify:master Nov 13, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants