Skip to content

Persist rich text image settings after authors apply edits - #2898

Merged
ascorbic merged 8 commits into
mainfrom
fix/image-caption-save
Sep 26, 2026
Merged

ascorbic merged 8 commits into
mainfrom
fix/image-caption-save

Conversation

@scottbuscemi

@scottbuscemi scottbuscemi commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Image settings now persist after authors click Apply, so saving and reopening the post no longer drops caption, alt text, tooltip, size, or alignment changes.

It also keeps visible captions and tooltip titles as separate values across the admin and inline editors. Existing title-only image nodes still load their title as a caption, while an explicitly cleared caption stays cleared.

Related issue: Not linked.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: Not applicable; this is a bug fix.
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenCode and Codex with GPT-5.6 Sol

Screenshots / test output

After Apply, save, and reload in English, the image settings retain the caption, tooltip, dimensions, and alignment:

English image settings after saving and reopening

The same settings render correctly in Arabic RTL:

Arabic RTL image settings after saving and reopening

The cleared-caption regression was also verified after a full save and reload: the caption remains empty while the tooltip title remains present.

Image settings with an empty caption and retained tooltip after reload

Verified with:

  • pnpm format
  • pnpm build
  • pnpm lint:quick
  • pnpm --silent lint:json | jq '.diagnostics | length' → 0
  • pnpm typecheck
  • Focused core image tests: 17 passed
  • Focused admin image tests: 50 passed after the follow-up fix (64 passed across the broader image suite before it)
  • Rendered English and Arabic RTL save/reload journeys at 1440 × 1000, with no browser console errors

pr2898-english-after-reopen

pr2898-arabic-rtl-reopen

pr2898-cleared-caption-tooltip-retained

@changeset-bot

changeset-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3130949

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2898

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2898

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2898

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2898

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2898

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2898

emdash

npm i https://pkg.pr.new/emdash@2898

create-emdash

npm i https://pkg.pr.new/create-emdash@2898

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2898

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2898

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@2898

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2898

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2898

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2898

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@2898

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@2898

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2898

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2898

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2898

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2898

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2898

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2898

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2898

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2898

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2898

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2898

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2898

commit: 3130949

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-image-caption-save.try.emdashcms.com, https://fix-image-caption-save-emdash-playground.emdash-cms.workers.dev (commit 3130949)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ca02e845.try.emdashcms.com, https://ca02e845-emdash-playground.emdash-cms.workers.dev 3130949 2026-09-26T18:27:00.257Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://e5d7487c.try.emdashcms.com, https://e5d7487c-emdash-playground.emdash-cms.workers.dev 81b114c 2026-09-26T15:57:48.967Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://6ce483b2.try.emdashcms.com, https://6ce483b2-emdash-playground.emdash-cms.workers.dev 7fa9f23 2026-09-26T14:27:25.025Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://9e67667e.try.emdashcms.com, https://9e67667e-emdash-playground.emdash-cms.workers.dev 6e7ec6c 2026-09-26T14:16:47.462Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://569613a8.try.emdashcms.com, https://569613a8-emdash-playground.emdash-cms.workers.dev 6acd32b 2026-09-26T14:07:59.965Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://3bfc92be.try.emdashcms.com, https://3bfc92be-emdash-playground.emdash-cms.workers.dev 7f36c49 2026-09-26T13:47:59.258Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://653a3735.try.emdashcms.com, https://653a3735-emdash-playground.emdash-cms.workers.dev 4fd7f68 2026-09-03T19:53:41.237Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://cf122cd4.try.emdashcms.com, https://cf122cd4-emdash-playground.emdash-cms.workers.dev fe51872 2026-09-03T17:54:47.771Z Visit the dashboard ↗

@emdashbot emdashbot Bot 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.

This bug fix makes image attribute edits apply live in the admin panel and keeps captions and tooltip titles as separate values. That is the right problem and the right place to fix it: ImageNodeView already opens an ImageDetailPanel whose onUpdate calls TipTap's updateAttributes, so wiring every control directly to onUpdate is a clean way to persist edits as authors type. The frontend Image.astro renderer correctly picks up the new title field, and the converter types have been updated.

I checked:

  • The admin and inline ProseMirror ⇄ Portable Text converters.
  • The admin ImageExtension schema (it already declares caption, so the new field round-trips safely).
  • The frontend Image.astro render output.
  • The new and updated tests.
  • The changeset.

There is one real regression that contradicts the PR description: title-only legacy Portable Text image nodes lose their captions when loaded into the editor. The PM→PT half of the code has a fallback that reads title as caption only when the caption attribute is absent. But the PT→PM converters always add a caption attribute (as an empty string), so the fallback is never reached for legacy data. The new legacy tests pass because they construct raw ProseMirror JSON, not real Portable Text input, so they bypass the problematic code path.

Other than that, the changeset is clear and the changes are localized. There is also a small import-convention slip in the new test file.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond overlap and removed review/needs-review No maintainer or bot review yet labels Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Sep 3, 2026
@github-actions github-actions Bot mentioned this pull request Sep 7, 2026
11 of 19 tasks
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 11, 2026

@emdashbot emdashbot Bot 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.

This re-review checks the fixes since the previous COMMENTED review. The approach remains sound: wiring every image detail control directly to onUpdate is the right way to make image edits persist as authors type, and the converter-side separation of caption and title is the right place to keep the two values independent.

What I verified:

  • Legacy title-only fallback is fixed. In the current code, every PT→PM converter (admin PortableTextEditor, core portable-text-to-prosemirror, and InlinePortableTextEditor) now sets caption to title only when the block does not already carry a caption field. The PM→PT side preserves an explicitly empty caption when title is present. The new tests exercise real Portable Text input as well as raw PM JSON, so the prior regression concern is addressed.
  • Live edits propagate correctly. ImageDetailPanel now calls onUpdate on every text, dimension, and alignment change; the Save/Cancel flow is removed consistently in both inline and overlay variants.
  • Frontend rendering picks up title. Image.astro now passes title through to both <AstroImage> and the fallback <img>, and the render test pins the output.
  • Changeset is clear, present-tense, names the affected behavior, and describes both the persistence fix and the caption/title separation. It meets the .changeset/README.md guidance for a patch entry.

One real bug remains: the dimension handlers can propagate NaN into the live ProseMirror node because parseInt can return NaN for intermediate non-numeric input, and the existing truthiness guard treats NaN as a valid number. The aspect-ratio branch then computes Math.round(NaN / aspectRatio), producing NaN for both dimensions, which serializes to the node and renders as "NaNpx" widths/heights in the editor and on the rendered page. The fix is a small Number.isNaN guard before calling onUpdate.

Overall the PR is close; once the NaN path is guarded, it should be good to merge.

Comment on lines 96 to 116
const handleWidthChange = (value: string) => {
const newWidth = value ? parseInt(value, 10) : undefined;
const newHeight =
lockAspectRatio && aspectRatio && newWidth
? Math.round(newWidth / aspectRatio)
: displayHeight;
setDisplayWidth(newWidth);
if (lockAspectRatio && aspectRatio && newWidth) {
setDisplayHeight(Math.round(newWidth / aspectRatio));
}
setDisplayHeight(newHeight);
onUpdate({ displayWidth: newWidth, displayHeight: newHeight });
};

const handleHeightChange = (value: string) => {
const newHeight = value ? parseInt(value, 10) : undefined;
const newWidth =
lockAspectRatio && aspectRatio && newHeight
? Math.round(newHeight * aspectRatio)
: displayWidth;
setDisplayHeight(newHeight);
if (lockAspectRatio && aspectRatio && newHeight) {
setDisplayWidth(Math.round(newHeight * aspectRatio));
}
setDisplayWidth(newWidth);
onUpdate({ displayWidth: newWidth, displayHeight: newHeight });
};

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.

[needs fixing] The handleWidthChange and handleHeightChange handlers now call onUpdate live, but they do not guard against parseInt returning NaN. For an invalid intermediate value such as "e" or " " from a number input, value ? parseInt(value, 10) : undefined assigns NaN to newWidth/newHeight (because NaN is truthy). That NaN is then written into the ProseMirror node via updateAttributes(...) and can surface as "NaNpx" in the editor/published image styles.

Suggested change
const handleWidthChange = (value: string) => {
const newWidth = value ? parseInt(value, 10) : undefined;
const newHeight =
lockAspectRatio && aspectRatio && newWidth
? Math.round(newWidth / aspectRatio)
: displayHeight;
setDisplayWidth(newWidth);
if (lockAspectRatio && aspectRatio && newWidth) {
setDisplayHeight(Math.round(newWidth / aspectRatio));
}
setDisplayHeight(newHeight);
onUpdate({ displayWidth: newWidth, displayHeight: newHeight });
};
const handleHeightChange = (value: string) => {
const newHeight = value ? parseInt(value, 10) : undefined;
const newWidth =
lockAspectRatio && aspectRatio && newHeight
? Math.round(newHeight * aspectRatio)
: displayWidth;
setDisplayHeight(newHeight);
if (lockAspectRatio && aspectRatio && newHeight) {
setDisplayWidth(Math.round(newHeight * aspectRatio));
}
setDisplayWidth(newWidth);
onUpdate({ displayWidth: newWidth, displayHeight: newHeight });
};
const handleWidthChange = (value: string) => {
const parsed = value ? parseInt(value, 10) : undefined;
if (Number.isNaN(parsed)) return;
const newWidth = parsed;
const newHeight =
lockAspectRatio && aspectRatio && newWidth
? Math.round(newWidth / aspectRatio)
: displayHeight;
setDisplayWidth(newWidth);
setDisplayHeight(newHeight);
onUpdate({ displayWidth: newWidth, displayHeight: newHeight });
};
const handleHeightChange = (value: string) => {
const parsed = value ? parseInt(value, 10) : undefined;
if (Number.isNaN(parsed)) return;
const newHeight = parsed;
const newWidth =
lockAspectRatio && aspectRatio && newHeight
? Math.round(newHeight * aspectRatio)
: displayWidth;
setDisplayHeight(newHeight);
setDisplayWidth(newWidth);
onUpdate({ displayWidth: newWidth, displayHeight: newHeight });
};

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 11, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 81b114c Sep 26 2026, 03:58 PM

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026

@emdashbot emdashbot Bot 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.

The approach of this PR is sound: separate caption and title at the converter seams and wire image settings through onUpdate so they survive a save/reload cycle. The prior review's open items are fixed: PT→PM converters now only fall back to title when caption is absent, the PM→PT side preserves an explicit empty caption, non-finite dimensions are sanitized in both the panel and the renderers, and Image.astro now forwards title to the rendered image.

One real bug remains. The ImageDetailPanel still batches edits behind an Apply/Save button, which contradicts the PR title's claim that settings persist "as authors edit them" — edits only persist after Apply. More importantly, handleSave collapses an empty Caption field to caption: undefined, which removes the ProseMirror caption attribute. Both the admin convertPMNode and the core prosemirror-to-portable-text converters then interpret an absent caption as a legacy title-only block and restore the tooltip text as the caption, undoing the PR's explicit goal that "an explicitly cleared caption stays cleared." Fix handleSave to send the empty string as an explicit cleared value and add a panel-level regression test that clears the Caption field, clicks Apply, and asserts the resulting Portable Text keeps caption: "" while preserving title.

Once that is fixed and the PR title/description are aligned with the Apply/Save behavior, this should be good to merge.

@@ -246,8 +256,8 @@ export function ImageDetailPanel({
alt: alt || undefined,
caption: caption || undefined,

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.

[needs fixing] handleSave collapses an empty caption to undefined, which removes the caption attribute from the ProseMirror node. Both the admin convertPMNode and the core prosemirror-to-portable-text converters treat a missing caption as a legacy title-only block and fall back to title, so a caption the author intentionally clears is restored from the tooltip text on the next save/load. This contradicts the PR's stated goal that "an explicitly cleared caption stays cleared."

Send an empty string as an explicit cleared value instead:

Suggested change
caption: caption || undefined,
caption,

Add a regression test that clears the Caption field in the panel, clicks Apply, and asserts the resulting Portable Text keeps caption: "" while preserving title.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026
@ascorbic ascorbic changed the title Persist rich text image settings as authors edit Persist rich text image settings after authors apply edits Sep 26, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026

@emdashbot emdashbot Bot 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.

The approach remains sound: this PR separates caption and title at the converter seams and wires image settings through the detail panel’s onUpdate so they survive a save/reopen cycle. All of the prior review’s blockers are fixed:

  • ImageDetailPanel.handleSave now emits an empty string for an explicitly cleared caption instead of collapsing it to undefined, and a regression test verifies the cleared-caption/title case.
  • Width/height change handlers guard against non-finite intermediate values, and ImageNodeView and Image.astro sanitize dimensions before rendering.
  • Admin and core PT→PM converters only fall back to title for caption when caption is absent, and malformed/title-only legacy blocks are handled consistently.
  • Image.astro now forwards title to the rendered <img>.

One minor consistency item remains. The inline visual editor (InlinePortableTextEditor) now converts displayWidth/displayHeight to and from Portable Text, but the inline TipTap image schema was only extended with caption; it does not declare displayWidth or displayHeight. TipTap will ignore those attributes on load, so an image with custom display sizes will silently lose them during an inline-edit round trip. Add the missing attributes so the converter changes are actually preserved by ProseMirror.

The changeset names both affected packages and describes the user-facing fix, so it reads fine as a CHANGELOG entry.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026

@emdashbot emdashbot Bot 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.

The approach is the right one for the reported bug: this PR separates caption and title at the converter seams, wires the image detail panel’s onUpdate through handleSave, and guards dimensions against non-finite values. All of the prior review’s blockers are addressed:

  • ImageDetailPanel.handleSave now emits caption: "" for an explicitly cleared caption, and a regression test verifies the cleared-caption/title case.
  • Width/height change handlers guard against non-finite intermediate values, and ImageNodeView and Image.astro sanitize dimensions before rendering.
  • Admin and core PT→PM converters only fall back to title for caption when caption is absent, and malformed/title-only legacy blocks are handled consistently.
  • Image.astro now forwards title to the rendered <img>.
  • InlinePortableTextEditor now extends its inline image schema with displayWidth, displayHeight, and caption.

The user-facing changeset names both affected packages and describes the fix, so it reads fine as a CHANGELOG entry.

One round-trip issue remains in the inline visual editor. The admin and core converters use truthy string extraction (attrStr/collapsed conditionals) for caption and title, so empty values are omitted from Portable Text. The inline editor’s convertPMNode uses attrStrOpt, which preserves empty strings. Because convertPTBlock initializes missing captions/titles as "" in the ProseMirror node, an inline edit of any nearby text causes the save payload to include pointless title: "" (and sometimes caption: "") blocks, diverging from admin/core output and leaking empty title="" attributes to published <img> elements. A small helper that drops empty strings before deciding what to serialize fixes it.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026

@emdashbot emdashbot Bot 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.

This is the right fix for the reported regression: it separates caption and title at every converter seam, persists custom image dimensions through the inline editor, and guards dimensions against non-finite values. All of the prior review’s blockers are addressed in this revision.

What I checked:

  • ImageDetailPanel.handleSave now emits caption: "" so an explicitly cleared caption stays cleared, and the regression tests cover the cleared-caption + title case.
  • Dimension change handlers use imageDimension() to reject non-finite / non-positive input, and both ImageNodeView and Image.astro sanitize dimensions before rendering.
  • The admin PortableTextEditor and core converters only fall back to title for caption when caption is absent; legacy title-only blocks are handled consistently, including the malformed no-asset branch.
  • Image.astro now forwards title to the rendered <img> and AstroImage elements.
  • InlinePortableTextEditor extends the inline image schema with displayWidth, displayHeight, and caption, and its PM→PT converter uses truthy string extraction so empty caption/title values are dropped instead of serializing "" back into stored Portable Text.
  • Tests added across admin, core converters, inline editor, and render paths cover round-tripping, legacy fallback, cleared captions, and non-finite dimensions.
  • The changeset lists both affected packages and describes the observable fix for readers.

I did not find any remaining logic bugs, security issues, AGENTS.md convention violations, or follow-up blockers. The PR is clean.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/awaiting-author Reviewed; waiting on the author to respond labels Sep 26, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026

@emdashbot emdashbot Bot 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.

This is the right fix for the image settings regression, and this revision resolves every blocker from the previous review.

As a re-review, I concentrated on verifying the changes requested in the prior round:

  • Explicitly cleared captions stay cleared. ImageDetailPanel.handleSave now emits caption as-is (including ""), and the regression test covers the cleared-caption + retained-title case.
  • Non-finite dimensions are rejected everywhere. The new imageDimension() / attrDimension() helpers guard the panel, ImageNodeView, Image.astro, and both core converters; the dimension change handlers short-circuit on invalid parseInt results.
  • Title and caption round-trip independently across every seam. The admin PortableTextEditor, core prosemirror-to-portable-text and portable-text-to-prosemirror converters, and the inline InlinePortableTextEditor all use the same Object.hasOwn(...) fallback logic so legacy title-only blocks keep their visible caption while explicitly stored captions do not backfill from title.
  • Inline editor schema now carries displayWidth, displayHeight, and caption. This closes the gap where custom sizes were lost after any inline edit, and the unchanged-save test verifies dimensions survive a subsequent edit.
  • Malformed / asset-less title-only blocks get the legacy caption fallback in both admin and core converters, with regression coverage.
  • Rendered <img> and AstroImage elements forward title, and both English and RTL render paths filter non-finite dimensions.
  • Changeset lists both affected packages, uses the correct patch bump, and describes the observable author-facing fix.

I also spot-checked the new and updated tests, the import extension in image-metadata.test.ts, and the LQIP / link normalization comments; none violate the comment-discipline or convention requirements. No remaining logic bugs, security issues, AGENTS.md violations, or unaddressed prior findings.

The PR is clean.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 26, 2026
@ascorbic
ascorbic merged commit 8b1b585 into main Sep 26, 2026
44 checks passed
@ascorbic
ascorbic deleted the fix/image-caption-save branch September 26, 2026 19:23
@emdashbot emdashbot Bot mentioned this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants