Repository navigation
fix: application basic information is not displayed - #7940
Conversation
| const query=application.value?.work_flow?.nodes?.find(n=>n.id==='base-node')?.properties?.api_input_field_list?.map((f:any)=>{ | ||
| return `${f.variable}=${f.default_value}` | ||
| }).join('&') | ||
| if(query){ |
There was a problem hiding this comment.
The change is a good defensive fix, but it is only partially robust.
What the patch improves
Adding ?. before .map(...) prevents a crash when api_input_field_list is null or undefined.
Because optional chaining short-circuits the rest of the chain, this expression:
api_input_field_list?.map(...).join('&')will return undefined instead of throwing when api_input_field_list is nullish.
Potential issues
-
Non-array values still crash
Ifapi_input_field_listis a non-nullish non-array value, e.g. an object, then?.mapdoes not protect you becausemapis not a function:api_input_field_list?.map(...) // TypeError if map is undefined
Use
Array.isArray(...)or ensure the API type guarantees an array. -
No URL encoding
Variables and default values are inserted directly:`${f.variable}=${f.default_value}`If either contains
&,=, spaces,#, etc., the query string can break. UseURLSearchParamsorencodeURIComponent. -
Implicit string conversion
Ifdefault_valueis an object, array,null, orundefined, template literals produce values like[object Object],"null", or"undefined". Decide the expected serialization explicitly. -
anytype
f: anyhides type errors. Prefer a proper type for API input fields. -
Minor:
findcallback assumes every node is non-null
Ifnodescan contain nullish entries,n.idcan throw. Usen?.id === 'base-node'if necessary. -
Computed result type
The computed value can beundefinedwhen the field list is missing. If it is later interpolated into a URL, ensure a fallback such as?? ''.
Suggested safer implementation
const query = computed(() => {
const fields = application.value?.work_flow?.nodes
?.find(n => n?.id === 'base-node')
?.properties?.api_input_field_list
if (!Array.isArray(fields)) return ''
const params = new URLSearchParams()
fields.forEach((f: any) => {
if (f?.variable == null) return
params.append(f.variable, String(f.default_value ?? ''))
})
return params.toString()
})This version:
- Safely handles missing fields
- Guarantees a string result
- Properly URL-encodes values
- Avoids
.map(...).join(...)on a possibly non-array value
Verdict
The diff fixes the obvious nullish crash, but for production code I would still add array validation and URL encoding.
fix: application basic information is not displayed