Skip to content

Conversation

@larbish
Copy link
Contributor

@larbish larbish commented Oct 29, 2025

No description provided.

@vercel
Copy link

vercel bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
content-studio Ready Ready Preview Comment Oct 29, 2025 5:21pm

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 29, 2025

npm i https://pkg.pr.new/nuxt-content/studio/nuxt-studio@38

commit: 9c0fb56

const rootDocumentDraftItem = await activeTree.value.draft.create(rootDocument)

await activeTree.value.selectItemById(rootDocumentDraftItem.id)
await activeTree.value.selectItemByFsPath(rootDocumentDraftItem.id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing id (with collection prefix like docs/file.md) to selectItemByFsPath() and selectParentByFsPath() which expect fsPath (like file.md). This causes tree lookups to fail and root items to be selected instead of the intended items after create and duplicate operations.

View Details
📝 Patch Details
diff --git a/src/app/src/composables/useContext.ts b/src/app/src/composables/useContext.ts
index 15d6881..5285a12 100644
--- a/src/app/src/composables/useContext.ts
+++ b/src/app/src/composables/useContext.ts
@@ -100,7 +100,7 @@ export const useContext = createSharedComposable((
 
       const rootDocumentDraftItem = await activeTree.value.draft.create(rootDocument)
 
-      await activeTree.value.selectItemByFsPath(rootDocumentDraftItem.id)
+      await activeTree.value.selectItemByFsPath(rootDocumentDraftItem.fsPath)
     },
     [StudioItemActionId.CreateMediaFolder]: async (params: CreateFolderParams) => {
       const { fsPath } = params
@@ -117,13 +117,13 @@ export const useContext = createSharedComposable((
 
       unsetActionInProgress()
 
-      await activeTree.value.selectParentByFsPath(gitKeepMedia.id)
+      await activeTree.value.selectParentByFsPath(gitKeepMedia.fsPath)
     },
     [StudioItemActionId.CreateDocument]: async (params: CreateFileParams) => {
       const { fsPath, content } = params
       const document = await host.document.create(fsPath, content)
       const draftItem = await activeTree.value.draft.create(document as DatabaseItem)
-      await activeTree.value.selectItemByFsPath(draftItem.id)
+      await activeTree.value.selectItemByFsPath(draftItem.fsPath)
     },
     [StudioItemActionId.UploadMedia]: async ({ parentFsPath, files }: UploadMediaParams) => {
       // Remove .gitkeep draft in folder if exists
@@ -191,7 +191,7 @@ export const useContext = createSharedComposable((
       if (item.type === 'file') {
         const id = generateIdFromFsPath(item.fsPath, item.collections![0])
         const draftItem = await activeTree.value.draft.duplicate(id)
-        await activeTree.value.selectItemByFsPath(draftItem!.id)
+        await activeTree.value.selectItemByFsPath(draftItem!.fsPath)
         return
       }
     },

Analysis

Incorrect ID vs fsPath usage causes tree selection failures after create and duplicate operations

What fails: selectItemByFsPath() and selectParentByFsPath() in useContext.ts receive full IDs with collection prefixes (e.g., "docs/file.md", "public-assets/.gitkeep") instead of fsPath values ("file.md", ".gitkeep"), causing tree lookups to fail and root items to be selected instead of the intended items

How to reproduce:

  1. Create a new document or media folder through the Studio UI
  2. The item should auto-select after creation, but root is selected instead
  3. Occurs in CreateDocumentFolder (line 103), CreateMediaFolder (line 120), CreateDocument (line 126), and DuplicateItem (line 194) actions

Result: Tree search functions findItemFromFsPath() and findParentFromFsPath() fail to match items because they compare item.fsPath (without prefix) against the provided ID parameter (with "docs/" or "public-assets/" prefix). Functions return null and select root item instead of newly created/duplicated item.

Expected: After create/duplicate operations, the new item should be auto-selected in the tree for immediate editing.

@larbish larbish merged commit b0e5c6a into main Oct 29, 2025
3 of 4 checks passed
@larbish larbish deleted the refactor/tree-fspath-based branch October 29, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants