fix(chat): guard prompts array before mapping in ToolsPopover#3081
Open
fix(chat): guard prompts array before mapping in ToolsPopover#3081
Conversation
Replaces `?? []` with `Array.isArray()` to prevent a crash when the
production virtual MCP endpoint returns a non-array value for `prompts`
(e.g. `{}`). The nullish coalescing operator only catches null/undefined,
so any other non-array shape slipped through and caused
`TypeError: I.map is not a function`.
Made-with: Cursor
Contributor
🧪 BenchmarkShould we run the Virtual MCP strategy benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
Contributor
Release OptionsSuggested: Patch ( React with an emoji to override the release type:
Current version:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
data?.prompts ?? []withArray.isArray(data?.prompts) ? data.prompts : []inToolsPopoverTypeError: I.map is not a functioncrash when the production virtual MCP endpoint returns a non-array value forprompts??operator only catchesnull/undefined— any other non-array shape (like an empty object) slips through and explodes on.mapRoot cause
When a
vir_*virtual MCP endpoint is used (instead of a directconn_*connection), the production server can return a different response shape forprompts/listwherepromptsis not an array. Locally this does not reproduce because the local virtual MCP returns a proper array or nothing at all.Test plan
{},null, orundefinedforpromptsMade with Cursor
Summary by cubic
Guard prompts before mapping in
ToolsPopoverto prevent a chat crash when the production virtual MCP endpoint returns a non-arraypromptsvalue. Replacesdata?.prompts ?? []withArray.isArray(data?.prompts) ? data.prompts : []so non-array shapes don’t break.map.Written for commit b6838e1. Summary will update on new commits.