-
Notifications
You must be signed in to change notification settings - Fork 93
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
runtime type consistency in expression evaluation. #221
Comments
I think not-rendering components as a fallback could be too over. How about passing a default value according to the type, like |
For example, we have a component It's quite ok if an application builder writes a wrong expression and accidentally fires the payment request because it's a user error. Falling back to any type-right value is dangerous because we do not know the semantics of the props are "pay the bill" or "do not pay the bill". |
If we add |
I think this is an issue of soundness. What's the expected behavior when a user writes a wrong expression like Responses I've thought about:
Of course, there may be some different ways to handle this in dev/production environments or in runtime/editor scope, but I think we can start from the specific one. |
Another problem, property value will change after toggle property from normal mode to JS mode. |
I think the runtime should catch the error and fall back to the property's Maybe it would cause the application to crash, but I think that is fine. Just like running the wrong JavaScript codes in v8 and the application would be crash too. And in the editor, when the expression fails to eval or the value is wrong, the editor should display the error in the properties form and the component wrapper like the image below. |
Yanzhen worries about it will cause silent bug if we fallback to default value. Maybe displaying error message maybe could avoid this problem. As to the default value, should we defind default value in spec? |
I think the component developers should handle the property's value could be Displaying the error messages could help the Sunmao users fix some expression errors but can't avoid them totally so I think we should handle the wrong expression in some ways.
Yes. When switching the JS mode, the expression string is hard to display by the other widgets. Thus, I think maybe set the property to the default value when switching the JS mode. In addition, I think we should also remain the |
I'm not sure about this. If the component developers declared the props like |
I think this is about when to crash. For example, when looking at the following code: function component(props) {
const UI = doSomething(props)
return render(UI)
}
function main() {
const props = evalProps(store)
return component(props)
}
main() If there is something happened in the |
https://github.com/webzard-io/sunmao-ui/blob/5fe5163733/packages/runtime/src/services/stateStore.ts#L106-L108
Currently, we handle expression evaluation errors with error logs but will return undefined as the result.
This makes components can not predict the types of props in runtime. For example, a component may define a props
foo
with typenumber
which is required, but if the evaluation throws an error, the component may getundefined
as thefoo
props value.Possible solution: do not render components in
ImplementWrapper
when expression evaluation failed.The text was updated successfully, but these errors were encountered: