Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

渲染时,文本前后空格的问题 #2624

Closed
beautiful-boyyy opened this issue Nov 9, 2023 · 24 comments
Closed

渲染时,文本前后空格的问题 #2624

beautiful-boyyy opened this issue Nov 9, 2023 · 24 comments
Assignees
Labels
help wanted Extra attention is needed / 老铁,赚 PR 的机会来了

Comments

@beautiful-boyyy
Copy link
Contributor

引擎会对设置器传过来的string类型的变量进行trim操作,个人认为没必要。string主要来源于string setter(input组件) 或者是 textArea setter(textArea组件),如果trim的话,将会使 textArea不能首行缩进,而且对于input来说,前后存在空格并不是什么大问题。

@JackLian JackLian added the help wanted Extra attention is needed / 老铁,赚 PR 的机会来了 label Nov 9, 2023
@JackLian
Copy link
Collaborator

JackLian commented Nov 9, 2023

也可以提个pr,给string setter增加一个配置项来控制是否trim

Copy link

github-actions bot commented Nov 9, 2023

Hello @beautiful-boyyy. We totally like your proposal/feedback, PR wanted。

你好 @beautiful-boyyy,我们完全同意你的提议/反馈,欢迎 PR。

@beautiful-boyyy
Copy link
Contributor Author

也可以提个pr,给string setter增加一个配置项来控制是否trim

Ok,我搞搞

@beautiful-boyyy
Copy link
Contributor Author

也可以提个pr,给string setter增加一个配置项来控制是否trim

可是这个是引擎的行为
Screenshot 2023-11-09 at 11 05 42

@liujuping
Copy link
Collaborator

@1ncounter 看一下渲染模块。这里我还发现两个其他的问题。

问题 1:packages/renderer-core/src/utils/common.ts 这里的 checkPropTypes 函数好像有问题。

image

比如下面的单测没有办法通过

it('should validate correctly with valid prop type', () => {
  const result = checkPropTypes(123, 'age', 'number', 'TestComponent');
  expect(result).toBe(true);
});

问题 2:packages/renderer-core/src/renderer/base.tsx 这里的 propType 一直是 undefined。

image

比如综合场景下的 Message 组件有定义 propType。

image

看看是代码问题还是使用问题。

@beautiful-boyyy
Copy link
Contributor Author

@1ncounter 看一下渲染模块。这里我还发现两个其他的问题。

问题 1:packages/renderer-core/src/utils/common.ts 这里的 checkPropTypes 函数好像有问题。

image

比如下面的单测没有办法通过

it('should validate correctly with valid prop type', () => {
  const result = checkPropTypes(123, 'age', 'number', 'TestComponent');
  expect(result).toBe(true);
});

问题 2:packages/renderer-core/src/renderer/base.tsx 这里的 propType 一直是 undefined。

image

比如综合场景下的 Message 组件有定义 propType。

image

看看是代码问题还是使用问题。

问题2在于调用的时候传了个空对象
Screenshot 2023-11-14 at 10 17 55

@liujuping
Copy link
Collaborator

@beautiful-boyyy 你的问题应该不存在。

image

image

对于 props 和 children 都是正常处理的,你截图的地方只是做了 check,没有直接使用该值。

@liujuping
Copy link
Collaborator

@1ncounter 看一下渲染模块。这里我还发现两个其他的问题。

问题 1:packages/renderer-core/src/utils/common.ts 这里的 checkPropTypes 函数好像有问题。

image

比如下面的单测没有办法通过

it('should validate correctly with valid prop type', () => {
  const result = checkPropTypes(123, 'age', 'number', 'TestComponent');
  expect(result).toBe(true);
});

问题 2:packages/renderer-core/src/renderer/base.tsx 这里的 propType 一直是 undefined。

image

比如综合场景下的 Message 组件有定义 propType。

image

看看是代码问题还是使用问题。

问题一已解决,并补充了相关的单测:#2646

@beautiful-boyyy
Copy link
Contributor Author

@beautiful-boyyy 你的问题应该不存在。

image

image

对于 props 和 children 都是正常处理的,你截图的地方只是做了 check,没有直接使用该值。

基础fusion组件demo,拖个button就不行,貌似放在区块才没trim

@liujuping
Copy link
Collaborator

建议先自查一下,
通过查看预览的 schema,区分一下是 schema 的问题还是其他
通过查看 Element,区分一下是 React 渲染的问题还是渲染器的问题。

@beautiful-boyyy
Copy link
Contributor Author

建议先自查一下, 通过查看预览的 schema,区分一下是 schema 的问题还是其他 通过查看 Element,区分一下是 React 渲染的问题还是渲染器的问题。

schema是正常的,element有问题

@liujuping
Copy link
Collaborator

那这个就是 React 渲染相关的问题了,可以去了解一下。

@beautiful-boyyy
Copy link
Contributor Author

那这个就是 React 渲染相关的问题了,可以去了解一下。

你意思是不是引擎的问题???

@liujuping
Copy link
Collaborator

可以写一个 React 组件,前后带上空格,看一下。

@beautiful-boyyy
Copy link
Contributor Author

可以写一个 React 组件,前后带上空格,看一下。

Screenshot 2023-11-15 at 10 49 58 react渲染没问题,感觉是引擎解析schema的逻辑出了问题

@liujuping
Copy link
Collaborator

element

那这里说的 element 的问题,截图详细说一下。或者提供可以直接导入复现的 schema。

@beautiful-boyyy
Copy link
Contributor Author

element

那这里说的 element 的问题,截图详细说一下。或者提供可以直接导入复现的 schema。

Screenshot 2023-11-15 at 11 00 24

@liujuping
Copy link
Collaborator

element

那这里说的 element 的问题,截图详细说一下。或者提供可以直接导入复现的 schema。

Screenshot 2023-11-15 at 11 00 24

@1ncounter 看了一下,的确有这个问题。可以排查一下是组件问题还是渲染器的问题。

@liujuping liujuping changed the title string 设置器的trim问题 渲染时,文本前后空格的问题 Nov 15, 2023
@1ncounter
Copy link
Collaborator

@liujuping 看了一下这个用例的文本显示问题原因有两个:一方面在__getComponentProps方法中调用 __parseProps 方法解析 props 时的将字符串 trim 掉了,另外将第一点的trim取消之后,button也进行了字符串的trim。

@liujuping
Copy link
Collaborator

@liujuping 看了一下这个用例的文本显示问题原因有两个:一方面在__getComponentProps方法中调用 __parseProps 方法解析 props 时的将字符串 trim 掉了,另外将第一点的trim取消之后,button也进行了字符串的trim。

可以先解决第一个问题,组件的问题可以让用户/物料侧解决。

@beautiful-boyyy
Copy link
Contributor Author

@liujuping 看了一下这个用例的文本显示问题原因有两个:一方面在__getComponentProps方法中调用 __parseProps 方法解析 props 时的将字符串 trim 掉了,另外将第一点的trim取消之后,button也进行了字符串的trim。

可以先解决第一个问题,组件的问题可以让用户/物料侧解决。

我来提个PR吧,不过我比较不解的是,为什么demo-general中放在自由布局里的button没问题...

@1ncounter
Copy link
Collaborator

@beautiful-boyyy 你的问题应该不存在。

image

image

对于 props 和 children 都是正常处理的,你截图的地方只是做了 check,没有直接使用该值。

@liujuping 奇怪的是我并没有复现这个例子。始终都是被 trim 过的

@1ncounter
Copy link
Collaborator

@liujuping 看了一下这个用例的文本显示问题原因有两个:一方面在__getComponentProps方法中调用 __parseProps 方法解析 props 时的将字符串 trim 掉了,另外将第一点的trim取消之后,button也进行了字符串的trim。

可以先解决第一个问题,组件的问题可以让用户/物料侧解决。

我来提个PR吧,不过我比较不解的是,为什么demo-general中放在自由布局里的button没问题...

@beautiful-boyyy 因为需要 render 的 children 是先经过处理的,props中的 children 会被这个 children 覆盖。
image
所以原先的处理是 children 会先进行parse不会被 trim,但是 props中的空格 会被 parseProps tirm 掉。
@liujuping 知悉一下

@1ncounter
Copy link
Collaborator

fixed with pr2654

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed / 老铁,赚 PR 的机会来了
Projects
None yet
Development

No branches or pull requests

5 participants