Skip to content

Commit 5dd4625

Browse files
liujupingJackLian
authored andcommitted
fix: fix low-code component rendering problems: 1. thisRequiredInJSE does not take effect 2. jsx components cannot obtain source components
1 parent 900b239 commit 5dd4625

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

packages/rax-simulator-renderer/src/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
523523
...extraProps,
524524
schema: _schema,
525525
components,
526-
designMode: renderer.designMode,
526+
designMode: '',
527527
device: renderer.device,
528528
appHelper: renderer.context,
529529
rendererName: 'LowCodeRenderer',
530+
thisRequiredInJSE: host.thisRequiredInJSE,
530531
customCreateElement: (Comp: any, props: any, children: any) => {
531532
const componentMeta = host.currentDocument?.getComponentMeta(Comp.displayName);
532533
if (componentMeta?.isModal) {

packages/react-simulator-renderer/src/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,11 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
450450
// 使用 _schema 为了使低代码组件在页面设计中使用变量,同 react 组件使用效果一致
451451
schema: _schema,
452452
components: renderer.components,
453-
designMode: renderer.designMode,
453+
designMode: '',
454454
device: renderer.device,
455455
appHelper: renderer.context,
456456
rendererName: 'LowCodeRenderer',
457+
thisRequiredInJSE: host.thisRequiredInJSE,
457458
customCreateElement: (Comp: any, props: any, children: any) => {
458459
const componentMeta = host.currentDocument?.getComponentMeta(Comp.displayName);
459460
if (componentMeta?.isModal) {

packages/renderer-core/src/renderer/base.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
116116
if (func) {
117117
if (isJSExpression(func) || isJSFunction(func)) {
118118
const fn = props.thisRequiredInJSE ? parseThisRequiredExpression(func, this) : parseExpression(func, this);
119-
return fn(props, state);
119+
return fn?.(props, state);
120120
}
121121

122122
if (typeof func === 'function') {
@@ -210,6 +210,14 @@ export default function baseRendererFactory(): IBaseRenderComponent {
210210
}
211211
};
212212

213+
_getComponentView = (componentName: string) => {
214+
const { __components } = this.props;
215+
if (!__components) {
216+
return;
217+
}
218+
return __components[componentName];
219+
};
220+
213221
__bindCustomMethods = (props = this.props) => {
214222
const { __schema } = props;
215223
const customMethodsList = Object.keys(__schema.methods || {}) || [];

packages/utils/src/build-components.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NpmInfo, ComponentSchema } from '@alilc/lowcode-types';
33
import { Component } from '@alilc/lowcode-designer';
44
import { isESModule } from './is-es-module';
55
import { isReactComponent, acceptsRef, wrapReactClass } from './is-react';
6+
import { isObject } from './is-object';
67

78
interface LibraryMap {
89
[key: string]: string;
@@ -76,6 +77,22 @@ function findComponent(libraryMap: LibraryMap, componentName: string, npm?: NpmI
7677
return getSubComponent(library, paths);
7778
}
7879

80+
/**
81+
* 判断是否是一个混合组件,即 components 是一个对象,对象值是 React 组件
82+
* 示例:
83+
* {
84+
* Button: ReactNode,
85+
* Text: ReactNode,
86+
* }
87+
*/
88+
function isMixinComponent(components: any) {
89+
if (!isObject(components)) {
90+
return false;
91+
}
92+
93+
return Object.keys(components).some(componentName => isReactComponent(components[componentName]));
94+
}
95+
7996
export function buildComponents(libraryMap: LibraryMap,
8097
componentsMap: { [componentName: string]: NpmInfo | ComponentType<any> | ComponentSchema },
8198
createComponent: (schema: ComponentSchema) => Component | null) {
@@ -89,6 +106,8 @@ export function buildComponents(libraryMap: LibraryMap,
89106
component = wrapReactClass(component as FunctionComponent);
90107
}
91108
components[componentName] = component;
109+
} else if (isMixinComponent(component)) {
110+
components[componentName] = component;
92111
} else {
93112
component = findComponent(libraryMap, componentName, component);
94113
if (component) {

0 commit comments

Comments
 (0)