-
Notifications
You must be signed in to change notification settings - Fork 79
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
fix: custom component name should be constrained explicitely - WF-52 #550
fix: custom component name should be constrained explicitely - WF-52 #550
Conversation
src/ui/src/custom_components/core.ts
Outdated
const is_valid_key = regex.test(key); | ||
if (!is_valid_key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JS, we prefer camlCase like isValidKey
.
const is_valid_key = regex.test(key); | |
if (!is_valid_key) { | |
const isValidKey = regex.test(key); | |
if (!isValidKey) { |
src/ui/src/custom_components/core.ts
Outdated
throw Error( | ||
`custom component key '${key}' is not valid. custom component should be declared with only alphanumeric lowercase and _.`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, do we really want to stop the application here ? Do you think console.warn
could be enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked myself the question. I decided to raise an explicit error. A simple warning might be enough. I will adapt this message in this case.
src/ui/src/custom_components/core.ts
Outdated
* | ||
* @param customComponents list of components in key-value form | ||
*/ | ||
export function declareCustomComponents( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function name could be more meaningfull. Maybe checkCustomComponents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I want to call the function like this declareCustomComponents
. It seems more logical when you read the calling code :
export default declareCustomComponents({
bubblemessage: BubbleMessage,
bubbleMessageadvanced: BubbleMessageAdvanced,
});
d426e9e
to
d8ffa7f
Compare
@madeindjs thanks for taking a look at this @FabienArcellier I think we should check during load, it'll be more straightforward and reliable. Also, let's try to keep We can intercept the keys here:
|
d8ffa7f
to
8990e9f
Compare
8990e9f
to
ef54bcc
Compare
I have implemented this approach. I continue looking for a better way to raise the error during the build or using a dedicated npm command. The problem only appears currently in runtime when you open the web application. It does not feel great. |
* feat: add a command npm run ui:custom.check
38fa575
to
7f89714
Compare
fix #517