fix(table-render): 数据源中的 React 元素被 object 判断吞掉导致单元格空白 - #1740
Open
Sunnan1998 wants to merge 1 commit into
Open
Sunnan1998 wants to merge 1 commit into
Sunnan1998 wants to merge 1 commit into
Conversation
## 问题 closes alibaba#1639 当 dataSource 的字段值直接是 JSX(为保持 columns 配置纯净,把渲染内容放在数据源中)时, 单元格渲染为空。 ## 原因 `renderDom` 中 `if (typeof val === 'object') return;` 未区分普通对象与 React 元素。 React 元素本质是对象,因此会命中该分支并返回 undefined。 ## 方案 在 object 判断前加入 `React.isValidElement(val)` 放行,命中则直接返回该元素。 - 位置选在 `renderTags` 之后、object 判断之前,为最小侵入点 - `item.enum` 分支已有 `!isObject(val)` 守卫,React 元素原本不会进入,无冲突 - 对既有非元素值的行为完全无变更
|
@Sunnan1998 is attempting to deploy a commit to the Faberon Team on Vercel. A member of the Team first needs to authorize it. |
|
您好,您发我的邮件我已收到,我会尽快回复的。谢谢。。。
|
This branch has not been deployed
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.
问题
closes #1639
当 dataSource 的字段值直接是 JSX 时(为保持 columns 配置纯净,把渲染内容放在数据源中),
单元格渲染为空白。
原因
renderDom中if (typeof val === 'object') return;未区分普通对象与 React 元素。React 元素本质是对象,因此命中该分支并返回 undefined。
方案
在 object 判断前加入
React.isValidElement(val)放行,命中则直接返回该元素。renderTags之后、object 判断之前,为最小侵入点item.enum分支已有!isObject(val)守卫,React 元素原本不会进入,无冲突因此对既有行为无任何变更