fix(chat): handle non-array children in fallback text and Actions types#225
Open
Ehesp wants to merge 2 commits intovercel:mainfrom
Open
fix(chat): handle non-array children in fallback text and Actions types#225Ehesp wants to merge 2 commits intovercel:mainfrom
Ehesp wants to merge 2 commits intovercel:mainfrom
Conversation
- Add getChildrenArray() to normalize children (array/single/undefined) for JSX/serialization
- Use getChildrenArray in cardToFallbackText and cardChildToFallbackText (cards.ts and markdown.ts BaseFormatConverter) to fix 'element.children.map is not a function'
- Unify ActionsComponent overloads so Actions([...]) type-checks when nested in Card({ children: [...] })
- Add tests for getChildrenArray and fallback text with non-array children
Made-with: Cursor
Contributor
|
@Ehesp is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
Hello,
This PR fixes two related issues that showed up when using cards built with JSX or after serialization, and when nesting
Actions([...])inside Card({ children: [...] }).For section and fields nodes, the fallback-text path assumed children was always an array and called
child.children.map(...). After JSX or serialization, children can be a single value orundefined, which led toelement.children.mapis not a function.Using the documented array form
Actions([Button(...), Button(...)])insideCard({ children: [...] })caused a type error. The inner array was inferred asCardChild[], so it didn’t match the strict action-children overload and also didn’t matchContainerProps, giving:"Type 'ChatElement[]' has no properties in common with type 'ContainerProps'":Essentially:
This PR does:
Introduces
getChildrenArray(node), which always returns an array: it keeps arrays as-is, wraps a single child in[child], and returns[]when children is missing or null. It uses it everywhere we iterate over children in the fallback-text path (in bothcards.tsandmarkdown.ts’sBaseFormatConverter), so we never call .map on a non-array.Updates
ActionsComponentso the array form is a single overload that acceptsreadonly CardChild[] | readonly ActionsChild[] | ActionsChild[]. That wayActions([...])type-checks both on its own and when nested inCard({ children: [...] }), without adding overloads that would trigger the “unified type signatures” lint.Test plan
Added tests to PR.