Repository navigation
fix: keep a cleared field empty in the downloaded image - #217
Merged
Merged
Conversation
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.
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.
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:
buildOgQuery(src/lib/url-builder.ts). A field the user cleared goes in askey=when its default isn't empty. Other empty values are still left out, so URLs don't get longer.mergeOgParamstakes the template's fields, and an optionaltextortextareafield sent empty now stays empty. Leaving the param out still gives the default.imageUrl=,logoUrl=ortemplate=returns an error instead of the default #166), required fields liketitle, colors, numbers and selects. Called without fields,mergeOgParamsbehaves exactly as it did.How I tested this
npm run check(0 errors),npm run test(917 tests, 38 files) andnpm run buildpass.buildOgQuerykeepskey=only for cleared fields with a non-empty default;mergeOgParamskeeps 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 withsubscriberCount: ''forsubscriberCount=and with the default when it's left out. With the three source files reset todev, 6 of the new tests fail; the 2 that pass are the fallback guards.npm run dev: cleared Subscriber Count on Subscribe Card and clicked Download PNG. The request hassubscriberCount=, and/api/ogrenders 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/ogdoes.npm run check,npm run test(1286 tests) andnpm run buildpass.