GeezerVison is showing github.com — fix: Fix the rendering error caused by incorrect key value when confi… · profencer/lowcode-engine@1026763
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "plugins": [ | | 3 | + "build-plugin-component", | | 4 | + "@alilc/lowcode-test-mate/plugin/index.ts" | | 5 | + ] | | 6 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/jest.config.js -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -const esModules = [ | 2 | | - '@alilc/lowcode-datasource-engine', | 3 | | -].join('|'); | 4 | | - | 5 | 1 | module.exports = { | 6 | 2 | transform: { | 7 | 3 | '^.+\\.(ts|tsx)$': 'ts-jest', | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | "es" | 11 | 11 | ], | 12 | 12 | "scripts": { | | 13 | + "test": "build-scripts test --config build.test.json", | 13 | 14 | "build": "build-scripts build --skip-demo" | 14 | 15 | }, | 15 | 16 | "dependencies": { | |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/base.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -565,7 +565,7 @@ export default function baseRendererFactory(): IBaseRenderComponent { | 565 | 565 | engine?.props?.onCompGetCtx(schema, scope); | 566 | 566 | } | 567 | 567 | 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) { | 569 | 569 | // 仅当循环场景走这里 | 570 | 570 | props.key = idx; | 571 | 571 | } | |
Collapse file Copy file name to clipboard +51Lines changed: 51 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +`; |
Collapse file Copy file name to clipboard +108Lines changed: 108 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +}) |
|