Hydrogen Rich Text Metafield: Render the JSON Tree

A Hydrogen rich text metafield holds a JSON tree, not HTML. Shopify’s docs describe the rich_text_field value as JSON and the Storefront schema types it as a string, so printing it puts raw JSON on the page. On legacy Hydrogen (2026.4 and earlier) the RichText component renders that string. Hydrogen 2026.10 has no replacement, so there you write the renderer yourself, in about 60 lines.

We ran everything below on 4 December 2026 in Node 24.12 with @shopify/hydrogen 2026.4.9, @shopify/hydrogen-react 2026.4.6, React 19.2.3 and React Router 7.18.7, rendering to a string on the server. We did not query a store. The shape of the value comes from Shopify’s documentation and the package’s types, not from a live response.

What does the Storefront API return for a rich text field?

Ask for the metafield’s type and value:

query ProductCare($handle: String!) {
  product(handle: $handle) {
    title
    careGuide: metafield(namespace: "custom", key: "care_guide") {
      type
      value
    }
  }
}

That query validates against the 2026-04 Storefront schema bundled with @shopify/hydrogen-react, where Metafield.value is String!. For this type, Shopify’s list of metafield data types says the string holds a tree under a root node, and describes the field as supporting headings, lists, links, bold and italics. The package’s types name seven node types: root, heading, paragraph, text, link, list and list-item. Here is a value built to that shape, spread over several lines for reading:

{"type": "root", "children": [
  {"type": "heading", "level": 1, "children": [{"type": "text", "value": "Care guide"}]},
  {"type": "paragraph", "children": [
    {"type": "text", "value": "Wash at 30 degrees.\nDo not tumble dry. "},
    {"type": "text", "value": "Never bleach.", "bold": true},
    {"type": "text", "value": " See our "},
    {"type": "link", "url": "/pages/returns", "title": "Returns policy",
      "children": [{"type": "text", "value": "returns policy"}]},
    {"type": "text", "value": "."}
  ]},
  {"type": "list", "listType": "unordered", "children": [
    {"type": "list-item", "children": [{"type": "text", "value": "100% cotton"}]},
    {"type": "list-item", "children": [{"type": "text", "value": "Made in Portugal", "italic": true}]}
  ]}
]}

If careGuide itself is null, either the product has no value or the Storefront API is not allowed to read it, and our post on Storefront API metafields that return null covers the second case.

We built that sample from the doc and did not copy it from a store. The doc’s own heading sample puts the heading inside a paragraph, and RichText rendered that one as <p><h1>, which is invalid HTML. Log a real value from your store before trusting any sample, ours included.

A Liquid theme has a filter for this: metafield_tag renders the field inside a <div class="metafield-rich_text_field">.

How do you render a Hydrogen rich text metafield?

On legacy Hydrogen, import RichText from @shopify/hydrogen and pass the string as data. This wrapper guards the empty case and changes two defaults:

import {RichText} from '@shopify/hydrogen';

type MetafieldLike = {type: string; value: string} | null | undefined;

export function CareGuide({metafield}: {metafield: MetafieldLike}) {
  if (metafield?.type !== 'rich_text_field') return null;

  return (
    <RichText
      as="section"
      className="care-guide"
      data={metafield.value}
      components={{
        root: ({node}) => <>{node.children}</>,
        heading: ({node}) => {
          const Tag = `h${Math.min(node.level + 1, 6)}` as 'h2';
          return <Tag>{node.children}</Tag>;
        },
      }}
    />
  );
}

Rendered inside a router with the value above, it produced this (we added the line breaks between blocks):

<section class="care-guide">
<h2>Care guide</h2>
<p>Wash at 30 degrees.<br/>Do not tumble dry. <strong>Never bleach.</strong> See our <a title="Returns policy" href="/pages/returns" data-discover="true">returns policy</a>.</p>
<ul>
<li>100% cotton</li>
<li><em>Made in Portugal</em></li>
</ul>
</section>

With data as the only prop, the same value came out as <div><div><h1>Care guide</h1> and so on. There are two wrappers because the as element, a div unless you say otherwise, wraps the root node, which is also a div. as="section" replaces the outer one and the root override removes the inner one. Extra props such as className land on the outer element.

A newline inside a text node became <br/>. Text nodes go through React as text, so a value containing <script> came out escaped.

Why does RichText throw a parsing error?

The message is [h2:error:RichText] Parsing error. Make sure to pass a JSON string of rich text metafield, and we produced it three ways.

The first was data={undefined}, which is what product.careGuide?.value gives you when the metafield comes back null. The second was the parsedValue that parseMetafield returns, because that is already an object. The third was a string of HTML, <p>Hello</p>. Each time the original SyntaxError was on the error’s cause. The error is thrown while rendering, so an unguarded component fails the render for every product that lacks the field. Checking type first, as CareGuide does, covers all three.

The plain prop has a variant of this. We put a node type the component does not know (table) into a value. Normal rendering dropped that node and its children silently. With plain set, the same value threw the parsing error, with Unknown node encountered table as the cause.

Which defaults are worth overriding?

Heading levels come straight from the value, so a level 1 heading in a metafield becomes a second <h1> on a product page whose title already has one. The heading override above pushes every level down by one.

Hydrogen’s RichText renders links through React Router’s <Link> with prefetch="intent". In our render /pages/returns became a router link and an absolute https:// URL became a plain anchor. Outside a router, in a unit test for example, the component threw a TypeError about basename as soon as the value held a link. The copy of RichText in @shopify/hydrogen-react renders a plain <a> and needs no router.

We could not check what the admin’s editor stores when a merchant links to one of their own products. If it stores an absolute URL on the shop’s domain, the default link will treat it as external. That is one more reason to read a real value.

Since 2026.4.9 the default link components also refuse any URL whose protocol is not http, https, mailto, tel or sms, and render the link text on its own. The list is in the package source, and the Hydrogen changelog records the change. On 2026.4.8 a data: URL went straight into href in our test. That check lives in the default link only. Our own link override, which copied node.url into href, let the same data: URL through on 2026.4.9, so an override has to do its own check.

What replaces RichText on Hydrogen 2026.10?

Nothing in the package does. The reference page for the current version, 2026-10 as of December 2026, says “Not supported in this version”, and Shopify’s migration guide lists RichText beside parseMetafield() with the instruction “Your own code. Hydrogen 2026-10 has no replacement.” We checked the 2026.10.4 package, npm’s latest on 4 December 2026, and neither @shopify/hydrogen nor @shopify/hydrogen/react exports it. Our Hydrogen 2026.10 migration notes cover the rest of that move.

@shopify/hydrogen-react 2026.4.6 did install beside 2026.10.4 in a scratch project and rendered the sample to the same HTML as before. It is still a 2026.4 package, with no 2026.10 release on npm as of December 2026, so we would not start new work on it. Seven node types is little enough to render yourself:

import {Fragment, type ReactNode} from 'react';

type Node = {
  type: string;
  value?: string;
  bold?: boolean;
  italic?: boolean;
  level?: number;
  listType?: string;
  url?: string;
  title?: string;
  target?: string;
  children?: Node[];
};

const SAFE = ['http:', 'https:', 'mailto:', 'tel:'];

function isSafe(url?: string): url is string {
  if (typeof url !== 'string') return false;
  try {
    return SAFE.includes(new URL(url, 'https://base.invalid').protocol);
  } catch {
    return false;
  }
}

function render(node: Node, key: number): ReactNode {
  const kids = node.children?.map(render);
  switch (node.type) {
    case 'heading': {
      const Tag = `h${Math.min((node.level ?? 1) + 1, 6)}` as 'h2';
      return <Tag key={key}>{kids}</Tag>;
    }
    case 'paragraph':
      return <p key={key}>{kids}</p>;
    case 'list': {
      const Tag = node.listType === 'ordered' ? 'ol' : 'ul';
      return <Tag key={key}>{kids}</Tag>;
    }
    case 'list-item':
      return <li key={key}>{kids}</li>;
    case 'link':
      if (!isSafe(node.url)) break;
      return (
        <a key={key} href={node.url} title={node.title} target={node.target}>
          {kids}
        </a>
      );
    case 'text': {
      let out: ReactNode = (node.value ?? '').split('\n').map((line, i) => (
        <Fragment key={i}>
          {i > 0 && <br />}
          {line}
        </Fragment>
      ));
      if (node.bold) out = <strong>{out}</strong>;
      if (node.italic) out = <em>{out}</em>;
      return <Fragment key={key}>{out}</Fragment>;
    }
  }
  return <Fragment key={key}>{kids}</Fragment>;
}

export function RichTextTree({json}: {json: string}) {
  return <>{render(JSON.parse(json), 0)}</>;
}

For the value above this produced exactly the HTML that RichText from @shopify/hydrogen-react did once its headings were demoted and both wrappers removed. It differs in one place on purpose: an unknown node keeps its children instead of vanishing. Swap the <a> for your router’s link when node.url starts with /, and keep guarding the null metafield in the caller.

How do you get plain text for a meta description?

plain renders the text inside the wrapper element, so it cannot hand a string to a route’s meta export. A short walker can:

type RichTextNode = {type: string; value?: string; children?: RichTextNode[]};

export function richTextToPlain(json: string): string {
  const parts: string[] = [];
  const walk = (node: RichTextNode) => {
    if (node.type === 'text') parts.push(node.value ?? '');
    node.children?.forEach(walk);
    if (node.type !== 'text' && node.type !== 'link') parts.push(' ');
  };
  walk(JSON.parse(json));
  return parts.join('').replace(/\s+/g, ' ').trim();
}

On the sample it returned Care guide Wash at 30 degrees. Do not tumble dry. Never bleach. See our returns policy. 100% cotton Made in Portugal. Trim it to length yourself. Our post on Hydrogen SEO meta tags shows where the description goes on each Hydrogen line.

Which should you use?

On a legacy storefront that is staying put for now, keep RichText. Guard on type, demote the headings, and move to 2026.4.9 for the link check. If a 2026.10 migration is planned, or you already override most node types, write the renderer now. The file imports nothing from Hydrogen, so it is the same on both versions, and it takes one item off the migration list.

Neither route helps when the content needs images, tables or embeds. Shopify describes the field as headings, lists, links, bold and italics, and the types hold nothing else. Content like that belongs in a page or an article, whose bodies the Storefront API returns as HTML.

We build Shopify storefronts on themes and on Hydrogen, along with the custom features a stock setup leaves out. If metafield content is not reaching your pages the way it was entered, that is part of our Shopify development work.

Need this built properly?

Get in touch

Hack the planet!