Fix undefined centerImage crashing article saves with images - #366
Merged
Famousmaster206 merged 1 commit intoAug 10, 2026
Merged
Conversation
CustomImage.save() in the EditorJS image tool copied _data.centerImage straight through, but centerImage is a custom action (not one of @editorjs/image's built-in tunes), so it is never initialized and stays undefined until an author explicitly toggles "Center image". Firestore's setDoc() rejects any field holding a literal undefined, which was the cause of the reported "Unsupported field value: undefined" errors when saving articles containing images.
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.
Description
Fixes the "ERROR SAVING ARTICLE: FirebaseError: [code=invalid-argument]: Function setDoc called with invalid data. Unsupported field value: undefined" bug that many users hit when saving an article containing an image.
Root cause:
CustomImage.save()insrc/components/article-creator/Editor.tsxreturnscenterImage: d.centerImage.centerImageis a custom action bolted onto the@editorjs/imagetool (viaconfig.actions), not one of the tool's built-in tunes (withBorder,withBackground,stretched). The base tool auto-initializes its built-in tunes tofalse, but has no knowledge ofcenterImage, so it stays a literalundefinedon_datauntil an author explicitly clicks the "Center image" toggle at least once.That
undefinedthen flows straight into the article's block data and gets written withsetDoc(). Firestore's client SDK rejects any field holding a literalundefined(this project doesn't setignoreUndefinedProperties), which is exactly the reported error. Since most authors never bother toggling "center image" on every image, this affects the large majority of articles containing images.Fix: coerce the value to a boolean before saving, the same way the built-in tunes already resolve to booleans:
This is a small, isolated fix — no other behavior changes.
Not tied to any other open PR/issue; found and fixed while investigating a live bug report on fivehive.org.
Pull request type
Please check the type of change your PR introduces:
Demo
No visual/UI change — this only affects what gets written to Firestore, not the editor UI or rendering.
How Has This Been Tested? How can the reviewer test it?
How it was tested:
@editorjs/image@2.10.3source to confirm the base tool only auto-initializeswithBorder,withBackground, andstretchedto booleans, nevercenterImage(which this repo adds separately as a custom action).CustomImage.save()produces (withcenterImage: undefined) and called the realfirebase/firestoresetDoc()against it directly — it threw the exact same error reported in production, including the same document-path format. Re-ran after applying the?? falsefix and confirmedsetDoc()passed local validation instead of throwing immediately.tsc --noEmit— no type errors.npm run build(next build) — succeeds, only pre-existing unrelated lint warnings.How a reviewer can test it:
main(before this fix), this reliably reproduces theERROR SAVING ARTICLEalert with theUnsupported field value: undefinedmessage.Checklist