Elements: Confirm before overwriting Element files - #9788
Merged
Conversation
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — returns a structured file-conflict response from the insert-element API when an existing .element.tsx file has different content, then prompts the user with side-by-side source previews before overwriting.
insertElementHandlerreturnsfile-conflictinstead of throwing — when an element file exists with different content andoverwriteExistingisfalse, the handler returns a structured conflict payload withexistingSourceandincomingSourceinstead of throwing anError.InsertElementResponsediscriminated union — the response type now has three branches:success: true,file-conflict(withInsertElementFileConflict), anderror(withreasonandstack).InsertElementRequestgainsoverwriteExisting: boolean.insertElementclient retries withoverwriteExisting: true— the client calls the API once without overwrite; on conflict, it shows the confirmation dialog, and on approval retries with the overwrite flag set.useElementOverwriteConfirmationhook — new confirmation dialog showing the conflicting file path, a warning, and expandable<details>blocks with existing and incoming source code previews.- Wired through
Canvas.tsxanduse-timeline-asset-drop.ts— both Element drop entry points pass the confirmation callback throughhandleDropintoinsertElement. - Undo stack captures original source — when overwriting, the undo snapshot stores the existing file content as
oldContentsso undo restores the prior version (previouslynull, which would delete on undo — not what you want after overwrite). - Server tests — four new test cases cover creation, identical-file reuse, structured conflict response (verifying no mutation), and overwrite-with-undo restore of both files.
DeepSeek Pro (free via Pullfrog for OSS) (Claude Opus not used — the program covers this model; add its provider key to run your pick) | 𝕏
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
.element.tsxchanges, with existing and incoming source previewsVerification
bun run buildbun run stylecheckbun test packages/studio-server/src/test/insert-element.test.tsCloses #9785