Skip to content

Commit 2f238d3

Browse files
committed
feat: 过滤掉不应该作为attribute传递的props
1 parent b0fc3b8 commit 2f238d3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/pro-components/chat/_util/reactify.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ const reactify = <T extends AnyProps = AnyProps>(
437437
const isSlotProp = prop.endsWith('Slot');
438438
const possibleSlotName = hyphenate(isSlotProp ? prop.slice(0, -4) : prop);
439439

440+
// react元素优先作为slot处理
441+
if (isReactElement(val)) {
442+
this.handleSlotProp(prop, val);
443+
return;
444+
}
445+
440446
// 将react组件的prop当做slot处理
441447
// 1. 检查webc中shadow dom是否存在该slot
442448
let hasSlotInDOM = this.ref.current?.shadowRoot?.querySelector(`slot[name="${possibleSlotName}"]`) !== null;
@@ -512,8 +518,16 @@ const reactify = <T extends AnyProps = AnyProps>(
512518

513519
render() {
514520
const { children, className, ...rest } = this.props;
515-
516-
return createElement(WC, { class: className, ...rest, ref: this.ref }, children);
521+
// 过滤掉不应该作为attribute传递的props,它们会在update()中处理
522+
const filteredProps: Record<string, any> = {};
523+
Object.keys(rest).forEach((key) => {
524+
const val = rest[key];
525+
// 仅允许基本类型作为 attribute 传递
526+
if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {
527+
filteredProps[key] = val;
528+
}
529+
});
530+
return createElement(WC, { class: className, ...filteredProps, ref: this.ref }, children);
517531
}
518532
}
519533

0 commit comments

Comments
 (0)