fix(api): keep images when a post also contains emoji nodes#338
Open
kytenz wants to merge 1 commit into
Open
Conversation
`contentJsonToMarkdown` only re-serializes `contentJson` when every node is in `RESERIALIZABLE_NODE_TYPES`. `emoji` was not, so any post written with the `:` emoji picker fell back to the stored markdown column — which is exactly the column that loses images (QuackbackIO#317). The result: a changelog entry with both a screenshot and an emoji came back from `GET /api/v1/changelog` (and MCP) with no images and with raw `:tada:` shortcodes. Teach `normalizeForMarkdown` about the node instead: emit the emoji's Unicode character (from `attrs.emoji` when the editor stored it, else the shortcode table), falling back to `:name:` for image-backed custom emoji that have no character. Images then survive alongside emoji, and the emoji read correctly in markdown consumers rather than as shortcodes.
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.
Problem
contentJsonToMarkdown()only re-serializescontentJsonwhen every node is inRESERIALIZABLE_NODE_TYPES.emojiwas not in that set, so any post written with the:emojipicker fell back to the stored
contentcolumn — which is precisely the column that loses images(the bug #317 fixed for everything else).
So a changelog entry containing both a screenshot and an emoji comes back from
GET /api/v1/changelog(and the MCP tools) with no images at all, and with raw:tada:shortcodes instead of the emoji. Mixing an image and an emoji in one post is common in changelogs,
so this quietly undoes #317 for a large share of real entries.
Reproduce: write a changelog entry in the editor with an uploaded image and one picker emoji,
publish it, then
GET /api/v1/changelog?published=true— the markdown has neither the image northe emoji character.
Fix
Teach
normalizeForMarkdown()about the node rather than excluding the whole document:emojijoinsRESERIALIZABLE_NODE_TYPESemojinode becomes a text node holding its Unicode character —attrs.emojiwhen the editorstored it, else the
@tiptap/extension-emojishortcode table (the same lookup orderrich-text-editor.tsxalready uses for HTML):name:— the text the editorround-trips them as
Images now survive alongside emoji, and emoji read as emoji in markdown consumers.
Tests
Three cases added to
markdown-tiptap.test.ts(40 pass)::tada:emoji doc → keepsand renders🎉, no leftover shortcodeattrs.emojiwins over the shortcode table:quackback_logo:bun run test apps/web/src/lib/server/__tests__/markdown-tiptap.test.ts— 40/40.Lint clean on both files. Repo-wide
typecheckis red onmainat 513 errors both with andwithout this change (pre-existing, unrelated to these files).