
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI've seen this issue before! The good news is there's a known solution for this specific problem with Portable Text links showing wrong URLs in Gatsby production builds.
This is actually a React key issue that only manifests in production builds due to how React optimizes rendering. The root cause is typically invalid HTML nesting in your custom serializers/components.
As the original poster discovered in the GitHub issue, the problem was having a <div> nested inside an <a> tag in their custom marks serializer. Block-level elements like div inside inline elements like a creates invalid HTML, which React handles differently in development vs production mode.
Change any block-level elements in your link marks to inline elements:
Bad:
marks: {
link: ({value, children}) => (
<a href={value.href}>
<div>{children}</div> // ❌ Block element inside inline
</a>
)
}Good:
marks: {
link: ({value, children}) => (
<a href={value.href}>
<span>{children}</span> // ✅ Inline element
</a>
)
}Or just use the children directly:
marks: {
link: ({value, children}) => (
<a href={value.href}>{children}</a>
)
}If you've already migrated to @portabletext/react (the modern replacement for the deprecated block-content-to-react), make sure you're also:
key props if you're mapping over custom componentsThis production-only bug with reused URLs is almost always a sign of invalid HTML nesting in your Portable Text components!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content backend


The only platform powering content operations


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store