fix(metadata): gate twitter app and player tags on card type - #2053
Merged
Conversation
The Twitter metadata renderer emitted `twitter:app:*` tags whenever a `twitter.app` object was present and `twitter:player:*` tags whenever `twitter.players` was present, regardless of the resolved card type. It also emitted `twitter:app:id`/`twitter:app:url` for falsy values (`0`, `""`). Next.js gates these blocks on the resolved card: `if (card === 'app')` and `if (card === 'player')`, and uses truthy checks for app id/url. Mirror that: gate the app block on `card === 'app'`, the player block on `card === 'player'`, and skip falsy app ids/urls. The card is already defaulted in postProcessMetadata (summary_large_image / summary), matching Next.js. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
commit: |
Member
|
/bigbonk review for issues |
Contributor
|
@james-elicx Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
twitter:app:*tags oncard === "app"andtwitter:player:*tags oncard === "player", instead of emitting them whenever atwitter.app/twitter.playersobject exists.twitter:app:id/twitter:app:urlvalues (0,"").Root Cause
The Twitter metadata renderer (
shims/metadata.tsx) gated the app block onif (tw.app)and the player block onif (tw.players)— purely on object presence, not on the resolved card type. So a user who settwitter: { app: {...} }while the card defaulted tosummarystill gottwitter:app:*tags (and the analogous problem for player cards). It also emittedtwitter:app:id/twitter:app:urlfor falsy values because it tested!== undefined.Next.js gates each sub-block on the resolved card (
if (card === 'app'),if (card === 'player')) and uses truthy checks for app id/url. The fix mirrors that: gate app oncard === "app", player oncard === "player", and use truthy checks. The card is already defaulted inpostProcessMetadata(summary_large_imagewhen images are present, elsesummary), matching Next.js'resolve-opengraphdefaulting, so the gate always compares against a resolved value.References
packages/next/src/lib/metadata/metadata.tsx(if (card === 'app')/if (card === 'player'), truthy id/url) andresolvers/resolve-opengraph.ts(card defaulting)Verification
CI=true pnpm test tests/file-based-metadata.test.ts tests/nextjs-compat/metadata.test.ts— new cases: notwitter:app:*when card isn'tapp; falsy app ids skipped while truthy ones emit; notwitter:player:*when card isn'tplayer; player tags emit when card isplayer. Red before, green after; existing twitter card tests still pass (71 passed).CI=true pnpm test— full battery green (only the pre-existing env flakesdeploy.test.ts > resolveWranglerBinandoxlint-prefer-shared-utils, reproduced identically onorigin/main).CI=true npx vp check— clean on both changed files.