Repository navigation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is a good defensive fix, but it is only partially robust.
What the patch improves
Adding
?.before.map(...)prevents a crash whenapi_input_field_listisnullorundefined.Because optional chaining short-circuits the rest of the chain, this expression:
will return
undefinedinstead of throwing whenapi_input_field_listis nullish.Potential issues
Non-array values still crash
If
api_input_field_listis a non-nullish non-array value, e.g. an object, then?.mapdoes not protect you becausemapis not a function: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
If
default_valueis an object, array,null, orundefined, template literals produce values like[object Object],"null", or"undefined". Decide the expected serialization explicitly.anytypef: anyhides type errors. Prefer a proper type for API input fields.Minor:
findcallback assumes every node is non-nullIf
nodescan contain nullish entries,n.idcan throw. Usen?.id === 'base-node'if necessary.Computed result type
The computed value can be
undefinedwhen the field list is missing. If it is later interpolated into a URL, ensure a fallback such as?? ''.Suggested safer implementation
This version:
.map(...).join(...)on a possibly non-array valueVerdict
The diff fixes the obvious nullish crash, but for production code I would still add array validation and URL encoding.