fix(types): address CodeRabbit review comments

groupNodeManage.ts:
- Add bounds checking before accessing node indices in link/external loops
- Fix selectedNodeInnerIndex getter with proper runtime guards
- Change storeModification section param to string | symbol, removing casts

asyncDialog.ts:
- Initialize #resolve with no-op function for defensive safety

api.ts:
- Add warning log for unexpected non-array queue prompts
This commit is contained in:
Johnpaul
2026-01-16 03:55:18 +01:00
parent 7321c6e19e
commit c1d763a6fa
3 changed files with 23 additions and 12 deletions

View File

@@ -67,7 +67,11 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
draggable: DraggableList | undefined
get selectedNodeInnerIndex(): number {
return +this.nodeItems[this.selectedNodeIndex!]!.dataset.nodeindex!
const index = this.selectedNodeIndex
if (index == null) throw new Error('No node selected')
const item = this.nodeItems[index]
if (!item?.dataset.nodeindex) throw new Error('Invalid node item')
return +item.dataset.nodeindex
}
constructor(app: ComfyApp) {
@@ -183,7 +187,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
storeModification(props: {
nodeIndex?: number
section: symbol
section: string | symbol
prop: string
value: unknown
}) {
@@ -238,7 +242,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
type: 'text',
onchange: (e: Event) => {
this.storeModification({
section: section as unknown as symbol,
section,
prop: String(prop),
value: { name: (e.target as HTMLInputElement).value }
})
@@ -251,7 +255,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
disabled: !checkable,
onchange: (e: Event) => {
this.storeModification({
section: section as unknown as symbol,
section,
prop: String(prop),
value: { visible: !!(e.target as HTMLInputElement).checked }
})
@@ -477,18 +481,22 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
}
// Rewrite links
const nodesLen = groupNodeData.nodes.length
for (const l of groupNodeData.links) {
if (l[0] != null)
l[0] = groupNodeData.nodes[l[0] as number].index!
if (l[2] != null)
l[2] = groupNodeData.nodes[l[2] as number].index!
const srcIdx = l[0] as number
const dstIdx = l[2] as number
if (srcIdx != null && srcIdx < nodesLen)
l[0] = groupNodeData.nodes[srcIdx].index!
if (dstIdx != null && dstIdx < nodesLen)
l[2] = groupNodeData.nodes[dstIdx].index!
}
// Rewrite externals
if (groupNodeData.external) {
for (const ext of groupNodeData.external) {
if (ext[0] != null) {
ext[0] = groupNodeData.nodes[ext[0] as number].index!
const extIdx = ext[0] as number
if (extIdx != null && extIdx < nodesLen) {
ext[0] = groupNodeData.nodes[extIdx].index!
}
}
}

View File

@@ -925,7 +925,10 @@ export class ComfyApi extends EventTarget {
type RawQueuePrompt = V1RawPrompt | CloudRawPrompt
const normalizeQueuePrompt = (prompt: RawQueuePrompt): TaskPrompt => {
if (!Array.isArray(prompt)) return prompt as TaskPrompt
if (!Array.isArray(prompt)) {
console.warn('Unexpected non-array queue prompt:', prompt)
return prompt as TaskPrompt
}
const fourth = prompt[3]
// Cloud shape: 4th is array (outputs), 5th is metadata object
if (Array.isArray(fourth)) {

View File

@@ -6,7 +6,7 @@ type DialogAction<T> = string | { value?: T; text: string }
export class ComfyAsyncDialog<
T = string | null
> extends ComfyDialog<HTMLDialogElement> {
#resolve!: (value: T | null) => void
#resolve: (value: T | null) => void = () => {}
constructor(actions?: Array<DialogAction<T>>) {
super(