[pull] main from BuilderIO:main#105
Merged
Merged
Conversation
… working (#4544) ## Problem The **Clear translation metadata** content action in the Smartling plugin was silently broken. Clicking the button and confirming the dialog appeared to succeed (snackbar showed \"Translation metadata cleared.\"), but the translation fields (`translationStatus`, `translationJobId`, etc.) were never actually removed from the content. ## Root Cause `content.meta` is a **MobX observable Map**. The button's `onClick` handler cloned it using `fastClone`: ```ts const updatedMeta = fastClone(content.meta); // fastClone = (obj) => JSON.parse(JSON.stringify(obj)) ``` `JSON.stringify` on a MobX observable Map serialises it as `{}` (an empty plain object) — Map entries are not picked up by the default JSON serialiser. As a result: - `updatedMeta` was always `{}` - The subsequent `delete updatedMeta.translationStatus` (etc.) calls were no-ops on a field that didn't exist - `updateLatestDraft` was called with `meta: {}`, either leaving the translation fields untouched (if the API merges) or wiping *all* metadata (if the API replaces) ## Fix Replace `fastClone(content.meta)` with `{ ...content.meta?.toJS() }`. `.toJS()` is the correct MobX API for converting an observable Map to a plain JS object. The spread then creates a regular mutable copy, and the `delete` operations work as intended. ```ts // Before const updatedMeta = fastClone(content.meta); // After const updatedMeta = { ...content.meta?.toJS() }; ``` This is exactly the same pattern already used in the backend's `cleanupOrphanedTranslationMetadata` helper ([`smartling.ts:465`](../blob/main/plugins/smartling/src/smartling.ts#L465)), confirming it's the correct approach. ## Test Plan - [ ] Open a content entry that has stale translation metadata (e.g. `translationStatus` = `completed` or `translationJobId` set, not in `pending`/`local`) - [ ] Open the content actions menu — confirm **Clear translation metadata** is visible - [ ] Click it and confirm the dialog - [ ] Verify the snackbar shows \"Translation metadata cleared.\" - [ ] Reload the content entry and confirm all 7 translation fields (`translationStatus`, `translationJobId`, `translationBy`, `translationRevision`, `translationRevisionLatest`, `translationBatch`, `translationRequested`) are gone from the meta - [ ] Confirm the **Clear translation metadata** button no longer appears for that entry 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Scoped UI fix for one content action and a patch version bump; no auth or broad meta-write path changes beyond correcting this handler. > > **Overview** > Fixes the **Clear translation metadata** content action so it actually removes Smartling fields instead of showing success while leaving metadata unchanged. > > The handler no longer clones `content.meta` with `fastClone` / `JSON.stringify`, which produced `{}` for MobX observable Maps. It now builds a plain object via `content.meta.toJS()` (with a fallback), deletes the seven translation keys, and persists with `updateLatestDraft`. The confirm dialog call matches the updated API shape. > > Plugin version is bumped to **0.1.2** in `package.json` and the lockfile. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 035fad6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Sanyam Kamat <1625114+sanyamkamat@users.noreply.github.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )