[PR #668] [MERGED] fix(avatar-crop): defensively skip non-legacy crops in editor and renderer #4720

Closed
opened 2026-10-22 04:10:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/668
Author: @Romuromylus
Created: 5/11/2026
Status: ✅ Merged
Merged: 5/11/2026
Merged by: @Romuromylus

Base: main ← Head: fix/avatar-crop-post-revert-defensive


📝 Commits (1)

  • bdb2b0c fix(avatar-crop): defensively skip non-legacy crops after revert

📊 Changes

2 files changed (+22 additions, -7 deletions)

View changed files

📝 packages/client/src/components/characters/CharacterEditor.tsx (+17 -5)
📝 packages/client/src/lib/utils.ts (+5 -2)

📄 Description

Linked issue

Closes #667

Why this change

After PR #666 reverted PR #661, any character whose extensions.avatarCrop was saved with the new `{srcX, srcY, srcWidth, srcHeight}` cropper (during the brief PR #661 window) now crashes the CharacterEditor on open:

TypeError: can't access property \"toFixed\", v.zoom is undefined

The reverted editor and renderer both assume the legacy zoom/offset shape and read .zoom directly. With foreign data present, the editor renders a blank screen and the avatar transform produces invalid CSS.

The repro is narrow (only users who beta-tested PR #661 and pulled the revert), but it's a hard crash that locks them out of the editor entirely.

What changed

  • packages/client/src/components/characters/CharacterEditor.tsx — replaces the unchecked cast on formData.extensions.avatarCrop with a runtime shape check. Only treats the saved value as a legacy crop when all three of zoom, offsetX, offsetY are numbers; anything else falls back to { zoom: 1, offsetX: 0, offsetY: 0 } so the slider starts fresh and the editor opens.
  • packages/client/src/lib/utils.ts — getAvatarCropStyle now guards on typeof crop.zoom === \"number\" before returning a transform. Foreign shapes render uncropped instead of producing scale(undefined) translate(undefined%, undefined%).

No data is rewritten. The user can re-edit the crop (which saves in the legacy shape, overwriting the foreign value) or just leave it — both editor and renderer are now tolerant.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify opening a character with a legacy-shape `avatarCrop` (just zoom + offsets) still renders unchanged in the editor — slider position matches the saved zoom, drag-to-pan works.
  • Manually verify opening a character with a foreign-shape `avatarCrop` (e.g. saved during PR #661 testing) no longer crashes. Editor opens, slider at 1.0×, preview shows the avatar uncropped. Re-saving the form should overwrite the foreign value with the legacy shape.
  • Manually verify opening a character with no `avatarCrop` extension at all renders identically to before.
  • Manually verify renderer surfaces (sidebar, chat header, message bubbles) still show legacy-cropped avatars correctly, and show foreign-shape crops uncropped instead of producing CSS warnings.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Defensive change; behavior matches the pre-#661 baseline except that foreign-shape data is now tolerated instead of crashing. No new screenshots vs the legacy editor flow.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/668 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/11/2026 **Status:** ✅ Merged **Merged:** 5/11/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/avatar-crop-post-revert-defensive` --- ### 📝 Commits (1) - [`bdb2b0c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bdb2b0c0eed57941d09e43f3a12a6664e32b726a) fix(avatar-crop): defensively skip non-legacy crops after revert ### 📊 Changes **2 files changed** (+22 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+17 -5) 📝 `packages/client/src/lib/utils.ts` (+5 -2) </details> ### 📄 Description ## Linked issue Closes #667 ## Why this change After PR #666 reverted PR #661, any character whose `extensions.avatarCrop` was saved with the new \`{srcX, srcY, srcWidth, srcHeight}\` cropper (during the brief PR #661 window) now crashes the CharacterEditor on open: > `TypeError: can't access property \"toFixed\", v.zoom is undefined` The reverted editor and renderer both assume the legacy zoom/offset shape and read `.zoom` directly. With foreign data present, the editor renders a blank screen and the avatar transform produces invalid CSS. The repro is narrow (only users who beta-tested PR #661 and pulled the revert), but it's a hard crash that locks them out of the editor entirely. ## What changed - `packages/client/src/components/characters/CharacterEditor.tsx` — replaces the unchecked cast on `formData.extensions.avatarCrop` with a runtime shape check. Only treats the saved value as a legacy crop when all three of `zoom`, `offsetX`, `offsetY` are numbers; anything else falls back to `{ zoom: 1, offsetX: 0, offsetY: 0 }` so the slider starts fresh and the editor opens. - `packages/client/src/lib/utils.ts` — `getAvatarCropStyle` now guards on `typeof crop.zoom === \"number\"` before returning a transform. Foreign shapes render uncropped instead of producing `scale(undefined) translate(undefined%, undefined%)`. No data is rewritten. The user can re-edit the crop (which saves in the legacy shape, overwriting the foreign value) or just leave it — both editor and renderer are now tolerant. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify opening a character with a legacy-shape \`avatarCrop\` (just zoom + offsets) still renders unchanged in the editor — slider position matches the saved zoom, drag-to-pan works. - Manually verify opening a character with a foreign-shape \`avatarCrop\` (e.g. saved during PR #661 testing) no longer crashes. Editor opens, slider at 1.0×, preview shows the avatar uncropped. Re-saving the form should overwrite the foreign value with the legacy shape. - Manually verify opening a character with no \`avatarCrop\` extension at all renders identically to before. - Manually verify renderer surfaces (sidebar, chat header, message bubbles) still show legacy-cropped avatars correctly, and show foreign-shape crops uncropped instead of producing CSS warnings. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Defensive change; behavior matches the pre-#661 baseline except that foreign-shape data is now tolerated instead of crashing. No new screenshots vs the legacy editor flow. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:05 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4720
No description provided.