mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
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:
@@ -67,7 +67,11 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
|
|||||||
draggable: DraggableList | undefined
|
draggable: DraggableList | undefined
|
||||||
|
|
||||||
get selectedNodeInnerIndex(): number {
|
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) {
|
constructor(app: ComfyApp) {
|
||||||
@@ -183,7 +187,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
|
|||||||
|
|
||||||
storeModification(props: {
|
storeModification(props: {
|
||||||
nodeIndex?: number
|
nodeIndex?: number
|
||||||
section: symbol
|
section: string | symbol
|
||||||
prop: string
|
prop: string
|
||||||
value: unknown
|
value: unknown
|
||||||
}) {
|
}) {
|
||||||
@@ -238,7 +242,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
|
|||||||
type: 'text',
|
type: 'text',
|
||||||
onchange: (e: Event) => {
|
onchange: (e: Event) => {
|
||||||
this.storeModification({
|
this.storeModification({
|
||||||
section: section as unknown as symbol,
|
section,
|
||||||
prop: String(prop),
|
prop: String(prop),
|
||||||
value: { name: (e.target as HTMLInputElement).value }
|
value: { name: (e.target as HTMLInputElement).value }
|
||||||
})
|
})
|
||||||
@@ -251,7 +255,7 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
|
|||||||
disabled: !checkable,
|
disabled: !checkable,
|
||||||
onchange: (e: Event) => {
|
onchange: (e: Event) => {
|
||||||
this.storeModification({
|
this.storeModification({
|
||||||
section: section as unknown as symbol,
|
section,
|
||||||
prop: String(prop),
|
prop: String(prop),
|
||||||
value: { visible: !!(e.target as HTMLInputElement).checked }
|
value: { visible: !!(e.target as HTMLInputElement).checked }
|
||||||
})
|
})
|
||||||
@@ -477,18 +481,22 @@ export class ManageGroupDialog extends ComfyDialog<HTMLDialogElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite links
|
// Rewrite links
|
||||||
|
const nodesLen = groupNodeData.nodes.length
|
||||||
for (const l of groupNodeData.links) {
|
for (const l of groupNodeData.links) {
|
||||||
if (l[0] != null)
|
const srcIdx = l[0] as number
|
||||||
l[0] = groupNodeData.nodes[l[0] as number].index!
|
const dstIdx = l[2] as number
|
||||||
if (l[2] != null)
|
if (srcIdx != null && srcIdx < nodesLen)
|
||||||
l[2] = groupNodeData.nodes[l[2] as number].index!
|
l[0] = groupNodeData.nodes[srcIdx].index!
|
||||||
|
if (dstIdx != null && dstIdx < nodesLen)
|
||||||
|
l[2] = groupNodeData.nodes[dstIdx].index!
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite externals
|
// Rewrite externals
|
||||||
if (groupNodeData.external) {
|
if (groupNodeData.external) {
|
||||||
for (const ext of groupNodeData.external) {
|
for (const ext of groupNodeData.external) {
|
||||||
if (ext[0] != null) {
|
const extIdx = ext[0] as number
|
||||||
ext[0] = groupNodeData.nodes[ext[0] as number].index!
|
if (extIdx != null && extIdx < nodesLen) {
|
||||||
|
ext[0] = groupNodeData.nodes[extIdx].index!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -925,7 +925,10 @@ export class ComfyApi extends EventTarget {
|
|||||||
type RawQueuePrompt = V1RawPrompt | CloudRawPrompt
|
type RawQueuePrompt = V1RawPrompt | CloudRawPrompt
|
||||||
|
|
||||||
const normalizeQueuePrompt = (prompt: RawQueuePrompt): TaskPrompt => {
|
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]
|
const fourth = prompt[3]
|
||||||
// Cloud shape: 4th is array (outputs), 5th is metadata object
|
// Cloud shape: 4th is array (outputs), 5th is metadata object
|
||||||
if (Array.isArray(fourth)) {
|
if (Array.isArray(fourth)) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ type DialogAction<T> = string | { value?: T; text: string }
|
|||||||
export class ComfyAsyncDialog<
|
export class ComfyAsyncDialog<
|
||||||
T = string | null
|
T = string | null
|
||||||
> extends ComfyDialog<HTMLDialogElement> {
|
> extends ComfyDialog<HTMLDialogElement> {
|
||||||
#resolve!: (value: T | null) => void
|
#resolve: (value: T | null) => void = () => {}
|
||||||
|
|
||||||
constructor(actions?: Array<DialogAction<T>>) {
|
constructor(actions?: Array<DialogAction<T>>) {
|
||||||
super(
|
super(
|
||||||
|
|||||||
Reference in New Issue
Block a user