fix: replace same-named files in place when uploading to the asset library - #1419
Merged
Merged
Conversation
…brary Dropping or uploading a file into an asset library folder that already had a file with the same name created a second entry with a duplicate name instead of updating the existing one. The upload flow now looks up an existing file by parent folder and name, replaces its file in place and fans the change out to docs that use the asset, matching the "Replace file" action in the asset details modal. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016L52aaKKrhphsmLBEupcti
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
Dropping (or uploading) files into an asset library folder that already contained files with the same names created a second entry per file with a duplicate name, instead of updating the existing asset.
The cause:
AssetBrowser.uploadFiles()always calledcreateAssetFile(), which mints a fresh random asset id, and never checked whether the destination folder already had a file with that name.Changes
ui/utils/assets.ts: addfindAssetFile(parent, name), an equality query onparent+name(filtered totype: 'file'), with the same parent-path normalization aslistAssets().ui/components/AssetBrowser/AssetBrowser.tsx: before creating an asset, look up an existing file by destination folder and filename. If one exists, replace its file in place viareplaceAssetFile()and fan the change out withsyncAssetToDocs(), matching the "Replace file" action in the asset details modal. The success notification reports how many existing files were replaced, and doc fan-out failures surface the same "Some docs failed to update" notification the details modal uses.assets.find.test.tscovering the lookup (folder scoping, case sensitivity, folders excluded, trailing-slash parent normalization).Applies to both the Assets page and the asset picker modal, since both use
AssetBrowser.Test plan
vitest run ui/utils/assets.find.test.ts ui/utils/assets.delete.test.tspasses.eslintandprettier --checkon changed files pass;tsc --noEmit -p tsconfig.build.jsonis clean.modifiedAt, new file src) and no duplicate appears. Docs that embed the asset pick up the new file.🤖 Generated with Claude Code
https://claude.ai/code/session_016L52aaKKrhphsmLBEupcti
Generated by Claude Code