Skip to content
Book a call

Declaring openGraph on one page deleted its share image

· 4-minute read · Engineering · by Direct Softworks

Next.js merges page metadata one key deep. A home page that only restated its locale lost the share card, the site name and the URL, and every check passed.

For four days, sharing our home page, or any page in the Romanian branch of the site, produced a bare link. No card, no image, no title block. Just the URL, sitting in the message like something pasted by mistake.

Blog posts and case studies unfurled perfectly. Nothing errored. The pages rendered, the type checker was happy, and the build was green. The only place the problem existed was in a handful of <meta> tags that were not there.

The cause on the home page was one line of metadata that set the Open Graph locale to en_GB. The root layout already said en_GB. That line added nothing, and it removed four things.

Metadata merges one level deep

In the Next.js App Router, each segment of a route (the root layout, a nested layout, the page) can export a metadata object, and Next combines them. It is tempting to picture that as a deep merge, where a page adds its own details on top of what its parents declared.

It is not. The Next.js documentation says metadata objects are shallowly merged, duplicate keys are replaced, and nested fields such as openGraph and robots defined in an earlier segment are overwritten by the last segment to define them. The resolver's code does exactly what that sentence says: when a segment exports openGraph, its object is resolved on its own and assigned in place of whatever the parent produced.

A page that sets one field inside openGraph deletes every field it did not set. Our root layout declared the type, the site name, the canonical site URL and the locale. The root folder also has an opengraph-image.tsx, which generates the 1200 by 630 card through the file convention. The home page's one-field declaration replaced all of it. The locale survived, because it was the one thing the page restated.

Why the blog posts were fine

This is the detail that made it hard to see, because the obvious comparison pointed the wrong way. Blog posts also declare openGraph, with their own title, description and type. They were not broken.

The difference was a file. The blog post route and the case study route each have their own opengraph-image.tsx in the same folder as the page. The resolver applies a file-based image only for the segment that file sits in, and only when that segment's own openGraph object has no images key.

So the card in the root folder reaches every page that declares no openGraph at all, and a card file in a parent folder does nothing for a child that writes openGraph. The posts worked because each had its own card file next to it. The home page and the Romanian pages had none.

The fix had two halves

The home page's declaration was deleted. It restated the parent, bought nothing, and cost the card, og:url, og:site_name and og:type.

The Romanian pages genuinely need their own openGraph: a ro_RO locale and their own URLs. Deleting it there was not an option, so each of those routes got its own opengraph-image.tsx, rendering the page's headline onto the card the same way a post does. Each one carries a comment at the top saying why it exists, so that nobody tidies it away as duplication.

The documentation suggests another route: pull the shared fields into one exported object and spread it into every page's openGraph. That works, and it relies on every future page remembering to spread it. We chose a rule that a reviewer can check by looking at a folder: every route that writes openGraph has a card file next to it, or sets images explicitly.

The only check that is real

Type checking cannot see this, because an openGraph object with one field is perfectly valid. A visual check cannot see it, because the page looks identical. The tag is simply absent from the HTML head.

So check the HTML head:

curl -s https://your-site/ro | grep -o '<meta property="og:image"[^>]*>'

No output means no card, whatever the code says. It is worth running that over every URL in the sitemap after a release, not only over the page you meant to change, because a layout or a shared metadata helper can take the card away from pages nobody opened.

The wider point

The bug is not really about share images. It is about inheritance that turns out to be replacement. You declare one small thing, expecting it to sit on top of the defaults, and the system reads your declaration as the complete answer.

We have met the same shape in robots.txt, where a matched group replaces the default instead of extending it, and it turns up in configuration files, CSS shorthand properties and API patch endpoints. Whenever you write a partial object into a system that has defaults, find out whether it merges or replaces, and find out from the output, not from the name of the feature.

More notes