Skip to content

Commit 1026763

Browse files
liujupingLeoYuan
authored andcommitted
fix: Fix the rendering error caused by incorrect key value when configuring the loop
1 parent d250242 commit 1026763

File tree

12 files changed

+720
-17
lines changed

12 files changed

+720
-17
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": [
3+
"build-plugin-component",
4+
"@alilc/lowcode-test-mate/plugin/index.ts"
5+
]
6+
}

packages/renderer-core/jest.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
const esModules = [
2-
'@alilc/lowcode-datasource-engine',
3-
].join('|');
4-
51
module.exports = {
62
transform: {
73
'^.+\\.(ts|tsx)$': 'ts-jest',

packages/renderer-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"es"
1111
],
1212
"scripts": {
13+
"test": "build-scripts test --config build.test.json",
1314
"build": "build-scripts build --skip-demo"
1415
},
1516
"dependencies": {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
565565
engine?.props?.onCompGetCtx(schema, scope);
566566
}
567567
props.key = props.key || `${schema.__ctx.lceKey}_${schema.__ctx.idx || 0}_${idx !== undefined ? idx : ''}`;
568-
} else if (typeof idx === 'number' && !props.key) {
568+
} else if ((typeof idx === 'number' || typeof idx === 'string') && !props.key) {
569569
// 仅当循环场景走这里
570570
props.key = idx;
571571
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`leafWrapper base 1`] = `
4+
<div
5+
_leaf={
6+
Node {
7+
"emitter": EventEmitter {
8+
"_events": Object {
9+
"onChildrenChange": [Function],
10+
"onPropChange": [Function],
11+
"onVisibleChange": [Function],
12+
},
13+
"_eventsCount": 3,
14+
"_maxListeners": undefined,
15+
Symbol(kCapture): false,
16+
},
17+
"hasLoop": false,
18+
"schema": Object {},
19+
}
20+
}
21+
>
22+
<div>
23+
content
24+
</div>
25+
</div>
26+
`;
27+
28+
exports[`leafWrapper change props 1`] = `
29+
<div
30+
_leaf={
31+
Node {
32+
"emitter": EventEmitter {
33+
"_events": Object {
34+
"onChildrenChange": [Function],
35+
"onPropChange": [Function],
36+
"onVisibleChange": [Function],
37+
},
38+
"_eventsCount": 3,
39+
"_maxListeners": undefined,
40+
Symbol(kCapture): false,
41+
},
42+
"hasLoop": false,
43+
"schema": Object {},
44+
}
45+
}
46+
>
47+
<div>
48+
new content
49+
</div>
50+
</div>
51+
`;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import renderer from 'react-test-renderer';
2+
import React from 'react';
3+
import { createElement } from 'react';
4+
import '../utils/react-env-init';
5+
import { leafWrapper } from '../../src/hoc/leaf';
6+
import components from '../utils/components';
7+
import Node from '../utils/node';
8+
9+
10+
const baseRenderer: any = {
11+
__debug () {},
12+
__getComponentProps (schema: any) {
13+
return schema.props;
14+
},
15+
__getSchemaChildrenVirtualDom () {},
16+
context: {
17+
engine: {
18+
createElement,
19+
}
20+
},
21+
props: {
22+
__host: {},
23+
getNode: () => {},
24+
__container: () => {},
25+
}
26+
}
27+
28+
describe('leafWrapper', () => {
29+
const Div = leafWrapper(components.Div as any, {
30+
schema: {
31+
id: 'div',
32+
},
33+
baseRenderer,
34+
componentInfo: {},
35+
scope: {},
36+
});
37+
38+
const DivNode = new Node({});
39+
const TextNode = new Node({});
40+
41+
const Text = leafWrapper(components.Text as any, {
42+
schema: {
43+
id: 'div',
44+
props: {
45+
content: 'content'
46+
}
47+
},
48+
baseRenderer,
49+
componentInfo: {},
50+
scope: {},
51+
});
52+
53+
const component = renderer.create(
54+
// @ts-ignore
55+
<Div _leaf={DivNode}>
56+
<Text _leaf={TextNode} content="content"></Text>
57+
</Div>
58+
);
59+
60+
it('base', () => {
61+
let tree = component.toJSON();
62+
expect(tree).toMatchSnapshot();
63+
});
64+
65+
it('change props', () => {
66+
TextNode.emitPropChange({
67+
key: 'content',
68+
newValue: 'new content',
69+
} as any);
70+
71+
let tree = component.toJSON();
72+
expect(tree).toMatchSnapshot();
73+
});
74+
});
75+
76+
77+
describe('loop', () => {
78+
const Div = leafWrapper(components.Div as any, {
79+
schema: {
80+
id: 'div',
81+
},
82+
baseRenderer,
83+
componentInfo: {},
84+
scope: {},
85+
});
86+
87+
const DivNode = new Node({});
88+
const TextNode = new Node({});
89+
90+
const Text = leafWrapper(components.Text as any, {
91+
schema: {
92+
id: 'div',
93+
props: {
94+
content: 'content'
95+
}
96+
},
97+
baseRenderer,
98+
componentInfo: {},
99+
scope: {},
100+
});
101+
102+
const component = renderer.create(
103+
// @ts-ignore
104+
<Div _leaf={DivNode}>
105+
<Text _leaf={TextNode} content="content"></Text>
106+
</Div>
107+
);
108+
})

0 commit comments

Comments
 (0)