Skip to content

Fixed false update state for API feature image captions#28107

Merged
aileen merged 2 commits into
TryGhost:mainfrom
aileen:aileen/onc-1765-feature-image-caption-dirty
May 28, 2026
Merged

Fixed false update state for API feature image captions#28107
aileen merged 2 commits into
TryGhost:mainfrom
aileen:aileen/onc-1765-feature-image-caption-dirty

Conversation

@aileen
Copy link
Copy Markdown
Member

@aileen aileen commented May 25, 2026

Summary

  • Prevented the feature image caption editor from writing Lexical hydration-only markup back to featureImageCaption when opening API-created posts.
  • Added an acceptance regression test proving the Update button remains disabled when a plain text feature image caption is loaded from the API.

Root cause

The nested caption editor normalizes plain text captions into Lexical-generated HTML on initialization. That initial normalization was written directly back to the Ember Data post model, marking published posts as dirty before any user edit.

Validation

  • pnpm --dir ghost/admin exec eslint app/components/gh-editor-feature-image.js tests/acceptance/editor/feature-image-test.js
  • pnpm --dir ghost/admin exec ember exam --split 1 --parallel=1 --filter='Acceptance: Feature Image'

closes ONC-1765
closes #28094

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Review Change Stack

Walkthrough

This PR adds caption HTML normalization and comparison logic to the feature image editor. New utility functions (cleanCaptionHtml, normalizeCaptionHtml, isLexicalPlainTextSpan) handle HTML parsing and unwrapping of Lexical plain-text SPAN elements. The setCaption action now normalizes both the new and current captions, compares them, and skips the update when the normalized content is equivalent. An acceptance test validates that API-provided feature image captions render correctly and the publish/save button remains disabled.

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fixed false update state for API feature image captions' accurately describes the main change: preventing false dirty state when loading API-created posts with feature image captions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly relates to the changeset, explaining the root cause, changes made, and validation steps for fixing the feature image caption editor.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@aileen aileen requested review from kevinansfield, mike182uk and sam-lord and removed request for kevinansfield May 25, 2026 06:37
Comment thread ghost/admin/app/components/gh-editor-feature-image.js
aileen added 2 commits May 28, 2026 08:13
closes [ONC-1765]([https://linear.app/ghost/issue/ONC-1765/oss-issue-update-button-incorrectly-enabled-on-load-when-feature-image](https://linear.app/ghost/issue/ONC-1765/oss-issue-update-button-incorrectly-enabled-on-load-when-feature-image))

The feature image caption editor was writing Lexical hydration markup back to `featureImageCaption` when API-created posts with plain text captions were opened, which marked the post as dirty before any user edit. Normalizing generated plain-text spans before comparing caption HTML keeps the loaded record clean while preserving real caption edits, and the regression test verifies the `Update` button remains disabled on load.
Documented why the feature image caption comparison ignores Lexical plain-text wrappers, matching the review request before merge.
@aileen aileen force-pushed the aileen/onc-1765-feature-image-caption-dirty branch from 0245d1b to 97b820d Compare May 28, 2026 04:13
@aileen aileen enabled auto-merge (squash) May 28, 2026 04:15
@aileen aileen merged commit 85da37b into TryGhost:main May 28, 2026
39 checks passed
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.

Update button incorrectly enabled on load when feature_image_caption is set via Admin API

2 participants