fix: 修复修改 readonly 属性时报错

This commit is contained in:
lihao.ylh 2021-08-23 19:07:03 +08:00
parent 9afa0771d1
commit 93f5c3b7b1
2 changed files with 8 additions and 1 deletions

View File

@ -159,7 +159,7 @@ class Renderer extends Component<{
suspended={renderer.suspended}
self={renderer.scope}
customCreateElement={(Component: any, props: any, children: any) => {
const { __id, __desingMode, ...viewProps } = props;
const { __id, __designMode, ...viewProps } = props;
viewProps.componentId = __id;
const leaf = documentInstance.getNode(__id) as Node;
if (isFromVC(leaf?.componentMeta)) {

View File

@ -47,6 +47,11 @@ function haveForceUpdate(instances: any[]): boolean {
return instances.every(inst => 'forceUpdate' in inst);
}
function isPropWritable(props: any, propName: string): boolean {
const descriptor = Object.getOwnPropertyDescriptor(props, propName);
return !!descriptor?.writable;
}
/**
*
* @param data
@ -69,6 +74,8 @@ export function supportsQuickPropSetting(data: ActivityData, doc: DocumentInstan
propKey &&
// 不是 extraProp
!propKey.startsWith('___') &&
// props[propKey] 有可能是 readyonly 的
instances.every(inst => isPropWritable(inst.props, propKey)) &&
!isJSSlot(value) &&
// functional component 不支持 ref.props 直接设值,是 readonly 的
isReactClass((doc.container?.components as any)[componentName]) &&