-
Notifications
You must be signed in to change notification settings - Fork 29
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
Check registered customElements before register it #107
Comments
Yeah, we have the same issue, I would open a new related issue but it is better to improve this one. We have the following component on React: import React, { useState } from '[email protected]';
import '[email protected]';
import nativeEvents from 'jsx-native-events';
import 'vanilla-colorful';
const styles = `
output {
display: block;
margin-top: 10px;
font-size: 1.25rem;
text-align: center;
}`;
export default function ColorExample() {
const [color, setColor] = useState('#1e88e5');
const handleColorChanged = (event: CustomEvent<{ value: string }>) => {
setColor(event.detail.value);
};
return (
<div>
<style>{styles}</style>
<hex-color-picker
color={color}
onEventColorChanged={handleColorChanged}
></hex-color-picker>
<output>{color}</output>
</div>
);
} From time to time we get the error: To fix it we opted to use import React, { useState } from '[email protected]';
import '[email protected]';
import 'vanilla-colorful';
import { HexColorPicker } from "vanilla-colorful/hex-color-picker.js";
const styles = `
output {
display: block;
margin-top: 10px;
font-size: 1.25rem;
text-align: center;
}`;
const ColorPicker = createComponent({
react: React,
tagName: "hex-color-picker",
elementClass: HexColorPicker,
events: {
onEventColorChanged: "color-changed" as EventName<
CustomEvent<{ value: string }>
>,
},
});
export default function ColorExample() {
const [color, setColor] = useState('#1e88e5');
const handleColorChanged = (event: CustomEvent<{ value: string }>) => {
setColor(event.detail.value);
};
return (
<div>
<style>{styles}</style>
<ColorPicker
color={color}
onEventColorChanged={(event) => setColor(event.detail.value)}
/>
<output>{color}</output>
</div>
);
} But, again, but less common than before, from time to time we have the same issue! @mnogono Could you open a PR with the fix? |
I suggest to add follow code snipped
customElements.get("xxx") || customElements.define("xxx")
This allow to prevent issue
Failed to execute 'define' on 'CustomElementRegistry': the name "hsva-color-picker" has already been used with this registry
The text was updated successfully, but these errors were encountered: