-
Notifications
You must be signed in to change notification settings - Fork 19
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
I'm experiencing an issue where (even after the recent refactor in #91) data collections cause the file tree to break.
I've made a minimal reproduction of the content schema that is causing the issue here: cc1aa9b
It seems that when the files are listed to generate the tree from, studio is currently unable to resolve the source for data collection items.
The browser console prints
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'include')
at parseSourceBase (source.ts:7:37)
at generateFsPathFromId (collection.ts:27:21)
at host.ts:206:28
at Array.map (<anonymous>)
at host.ts:204:28
at async Promise.all (:3000/index 3)
at async Object.list (host.ts:201:39)
at async handleDraftUpdate (useTree.ts:102:18)
at async useTree.ts:118:7
at async Object.load (useDraftBase.ts:211:5)
and the studio app fails to render any items in the tree.
As far as I can tell the error is caused by this function
studio/src/module/src/runtime/utils/source.ts
Lines 19 to 51 in 75f56ad
| export function getCollectionSourceById(id: string, sources: ResolvedCollectionSource[]) { | |
| const [_, ...rest] = id.split(/[/:]/) | |
| const prefixAndPath = rest.join('/') | |
| const matchedSource = sources.find((source) => { | |
| const prefix = source.prefix | |
| if (!prefix) { | |
| return false | |
| } | |
| if (!withLeadingSlash(prefixAndPath).startsWith(prefix)) { | |
| return false | |
| } | |
| let fsPath | |
| const [fixPart] = source.include.includes('*') ? source.include.split('*') : ['', source.include] | |
| const fixed = withoutTrailingSlash(withoutLeadingSlash(fixPart || '/')) | |
| if (fixed === prefix) { | |
| fsPath = prefixAndPath | |
| } | |
| else { | |
| const path = prefixAndPath.replace(prefix, '') | |
| fsPath = join(fixed, path) | |
| } | |
| const include = minimatch(fsPath, source.include, { dot: true }) | |
| const exclude = source.exclude?.some(exclude => minimatch(fsPath, exclude)) | |
| return include && !exclude | |
| }) | |
| return matchedSource | |
| } |
larsrickert
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working