fix(vfs): correct root entity selection when duplicates exist

When multiple root directory entities exist, initializeRoot() was using
the wrong field name to sort by creation time, causing it to select the
NEWER root (no children) instead of the OLDER root (with children).

Changed from metadata.createdAt (doesn't exist) to entity.createdAt
(correct field). This ensures VFS correctly uses the root with all the
Contains relationships.

Fixes Workshop File Explorer showing 0 files despite 579 VFS entities
being created during import.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-10-24 17:07:45 -07:00
parent 04dd8b2319
commit 7f4b1fd192
2 changed files with 4 additions and 3 deletions

View file

@ -177,9 +177,10 @@ export class VirtualFileSystem implements IVirtualFileSystem {
console.warn(`⚠️ Found ${existing.length} root entities! Using first one, consider cleanup.`)
// Sort by creation time - use oldest root (most likely to have children)
// v4.5.2: FIX - createdAt is at entity level, not metadata level!
existing.sort((a, b) => {
const aTime = a.metadata?.createdAt || a.metadata?.modified || 0
const bTime = b.metadata?.createdAt || b.metadata?.modified || 0
const aTime = (a as any).createdAt || a.metadata?.modified || 0
const bTime = (b as any).createdAt || b.metadata?.modified || 0
return aTime - bTime
})
}