Skip to content

fix: keep a cleared field empty in the downloaded image - #217

Merged
anurag629 merged 3 commits into
devfrom
fix/keep-cleared-fields
Oct 26, 2026
Merged

anurag629 merged 3 commits into
devfrom
fix/keep-cleared-fields

Conversation

@anurag629

@anurag629 anurag629 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Clearing an optional field in the editor hid it in the preview, but the downloaded PNG and the copied image URL brought the default back. The editor left empty values out of the URL, and the API fills in the template default for anything missing or empty. Subscribe Card's subscriber count says "leave empty to hide", and it never stayed hidden in the download. Pratham2511 ran into the same thing with the response fields in #207.

What changes:

  • The editor builds its URL with a new buildOgQuery (src/lib/url-builder.ts). A field the user cleared goes in as key= when its default isn't empty. Other empty values are still left out, so URLs don't get longer.
  • mergeOgParams takes the template's fields, and an optional text or textarea field sent empty now stays empty. Leaving the param out still gives the default.
  • Every other empty value falls back like before: the template, image URLs (An empty imageUrl=, logoUrl= or template= returns an error instead of the default #166), required fields like title, colors, numbers and selects. Called without fields, mergeOgParams behaves exactly as it did.
  • The API docs say how to leave a field blank.

How I tested this

  • npm run check (0 errors), npm run test (917 tests, 38 files) and npm run build pass.
  • New tests: buildOgQuery keeps key= only for cleared fields with a non-empty default; mergeOgParams keeps an optional text field sent empty, uses the default when it's left out, and still falls back for an empty required field, color and image; the route renders Subscribe Card with subscriberCount: '' for subscriberCount= and with the default when it's left out. With the three source files reset to dev, 6 of the new tests fail; the 2 that pass are the fallback guards.
  • In the editor on npm run dev: cleared Subscriber Count on Subscribe Card and clicked Download PNG. The request has subscriberCount=, and /api/og renders a different image for it (31,901 bytes) than for the default (38,359 bytes).

Update, 26 October

Merged the latest dev. The API Endpoint template's tests (#219, added after this PR) asserted the old behavior, a cleared response status coming back as "200 OK" in the download, so that test now expects it to stay empty like the preview, and its server helper passes the template's fields the way /api/og does. npm run check, npm run test (1286 tests) and npm run build pass.

Clearing an optional field in the editor hid it in the preview, but the
download and API URLs left the empty value out, so the API put the default
back. The editor now sends a cleared field as key= when its default isn't
empty, and the API keeps an optional text field that's sent empty. Leaving a
param out still gives the default, and empty templates, image URLs, required
fields, colors and numbers still fall back like before.
@anurag629
anurag629 merged commit 87ba7c0 into dev Oct 26, 2026
5 checks passed
@anurag629
anurag629 deleted the fix/keep-cleared-fields branch October 26, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant