Skip to content

Conversation

@larbish
Copy link
Contributor

@larbish larbish commented Nov 11, 2025

[Refactor] Separation of concern between app and module

Project Structure Overview

src/module

Nuxt module responsible for communication with the host (user’s website).
Handles all interactions with the SQLite database.

src/app

Frontend for the Nuxt Studio application.
Provides the user interface for CRUD operations on documents and media.
Communicate with the draft.

Refactor Goal

We want a clean separation of concerns between the app and the module.
Remove all usage of db id inside the app.
The app should operate only with fsPath.
Only the module (host side) resolves fsPath → id mapping and updates the DB (base of an agnostic framework CMS in the future)

Tree note

Each tree item can be a file or a folder
Files represent real documents (association fsPath <=> id in the Nuxt Content DB)
Folders are virtual items they don’t have a corresponding id in the DB.
They exist only in the app, as a way to group related files (documents or medias)

The module doesn’t deal with folders it only processes documents (with ids).

When folder actions are performed (e.g. delete, rename, revert), the app must handle them locally and contact the host only with the document/media ids affected by that action.

Resolves #56

@larbish larbish requested a review from farnabaz November 11, 2025 00:24
@vercel
Copy link

vercel bot commented Nov 11, 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 Nov 12, 2025 10:10am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 11, 2025

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

commit: 46cc6f6

Copy link

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

The list() method returns documents without the fsPath property, but the app expects all items to have fsPath when building the tree.

View Details
📝 Patch Details
diff --git a/src/module/src/runtime/host.ts b/src/module/src/runtime/host.ts
index 35dda02..1fa9861 100644
--- a/src/module/src/runtime/host.ts
+++ b/src/module/src/runtime/host.ts
@@ -197,9 +197,17 @@ export function useStudioHost(user: StudioUser, repository: Repository): StudioH
         return normalizeDocument(fsPath, item as DatabaseItem)
       },
       list: async (): Promise<DatabaseItem[]> => {
-        const collections = Object.keys(useContentCollections()).filter(c => c !== 'info')
-        const contents = await Promise.all(collections.map(async (collection) => {
-          return await useContentCollectionQuery(collection).all() as DatabaseItem[]
+        const collections = useContentCollections()
+        const collectionNames = Object.keys(collections).filter(c => c !== 'info')
+        const contents = await Promise.all(collectionNames.map(async (collectionName) => {
+          const items = await useContentCollectionQuery(collectionName).all() as DatabaseItem[]
+          const collection = collections[collectionName]
+          
+          // Normalize each item to include fsPath (similar to get() method)
+          return items.map(item => {
+            const fsPath = generateFsPathFromId(item.id, collection.source[0]!)
+            return normalizeDocument(fsPath, item)
+          })
         }))
 
         return contents.flat()

Analysis

Missing fsPath property in list() method breaks buildTree()

What fails: document.list() in src/module/src/runtime/host.ts returns items without fsPath property, causing buildTree() in src/app/src/utils/tree.ts to fail when accessing dbItem.fsPath

How to reproduce:

// Items from useContentCollectionQuery().all() lack fsPath property
const items = await host.document.list() // Returns items with id, stem, path but no fsPath
buildTree(items, null) // Throws: Cannot read properties of undefined (reading 'split')

Result: Runtime error Cannot read properties of undefined (reading 'split') when buildTree() tries to access dbItem.fsPath.split('/') on line 68

Expected: Items should include fsPath property like the get() method does by calling normalizeDocument(fsPath, item)

Source: Nuxt Content docs confirm default collection fields don't include fsPath

@larbish larbish merged commit 0b4068b into main Nov 12, 2025
3 of 4 checks passed
@larbish larbish deleted the refactor/remove-id-from-app-context branch November 12, 2025 10:08
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.

Can't find collection when prefix is /

3 participants