Skip to content

Fix undefined centerImage crashing article saves with images - #366

Merged
Famousmaster206 merged 1 commit into
AP-Students:mainfrom
saa938:fix/article-image-save-undefined-centerimage
Aug 10, 2026
Merged

Fix undefined centerImage crashing article saves with images#366
Famousmaster206 merged 1 commit into
AP-Students:mainfrom
saa938:fix/article-image-save-undefined-centerimage

Conversation

@saa938

@saa938 saa938 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

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() in src/components/article-creator/Editor.tsx returns centerImage: d.centerImage. centerImage is a custom action bolted onto the @editorjs/image tool (via config.actions), not one of the tool's built-in tunes (withBorder, withBackground, stretched). The base tool auto-initializes its built-in tunes to false, but has no knowledge of centerImage, so it stays a literal undefined on _data until an author explicitly clicks the "Center image" toggle at least once.

That undefined then flows straight into the article's block data and gets written with setDoc(). Firestore's client SDK rejects any field holding a literal undefined (this project doesn't set ignoreUndefinedProperties), 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:

centerImage: d.centerImage ?? false,

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:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

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:

  • Read the installed @editorjs/image@2.10.3 source to confirm the base tool only auto-initializes withBorder, withBackground, and stretched to booleans, never centerImage (which this repo adds separately as a custom action).
  • Wrote a standalone script that builds the same block-shaped object CustomImage.save() produces (with centerImage: undefined) and called the real firebase/firestore setDoc() against it directly — it threw the exact same error reported in production, including the same document-path format. Re-ran after applying the ?? false fix and confirmed setDoc() passed local validation instead of throwing immediately.
  • Ran tsc --noEmit — no type errors.
  • Ran npm run build (next build) — succeeds, only pre-existing unrelated lint warnings.

How a reviewer can test it:

  1. Open the article editor for any chapter, add an image block, upload/paste an image, and save without toggling the "Center image" setting.
  2. On main (before this fix), this reliably reproduces the ERROR SAVING ARTICLE alert with the Unsupported field value: undefined message.
  3. With this fix applied, the save succeeds normally regardless of whether "Center image" was ever toggled.

Checklist

  • I have performed a self-review of my own code

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.
Copilot AI lite review requested due to automatic review settings August 10, 2026 01:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@saa938 saa938 linked an issue Aug 10, 2026 that may be closed by this pull request
@saa938
saa938 requested a review from Famousmaster206 August 10, 2026 01:44

@Famousmaster206 Famousmaster206 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Famousmaster206
Famousmaster206 merged commit a6363a2 into AP-Students:main Aug 10, 2026
1 check passed
@saa938 saa938 mentioned this pull request Aug 11, 2026
8 tasks
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.

Adding images to article causes issues when saving

3 participants