fix: support hydrating elements with properties whose getters throw (#13211)

Fixes #10824
If during hydration a getter of a custom element was called, and that getter throwed, hydration would fail - this makes it not do that
pull/13231/head
Lucas Garron 3 months ago committed by GitHub
parent 1a9d8a509c
commit 80e30f7001
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -136,7 +136,13 @@ export function set_xlink_attribute(dom, attribute, value) {
*/
export function set_custom_element_data(node, prop, value) {
if (prop in node) {
var curr_val = node[prop];
// Reading the prop could cause an error, we don't want this to fail everything else
try {
var curr_val = node[prop];
} catch {
set_attribute(node, prop, value);
return;
}
var next_val = typeof curr_val === 'boolean' && value === '' ? true : value;
if (typeof curr_val !== 'object' || curr_val !== next_val) {
node[prop] = next_val;

@ -0,0 +1,16 @@
<script module>
if (!customElements.get('custom-element-with-settable-only-property')) {
customElements.define('custom-element-with-settable-only-property', class CustomElement extends HTMLElement {
set prop(n) {
this.value = n;
}
get prop() {
// invoking this getter shouldn't make hydration fail
throw new Error('This value is not gettable');
}
});
}
</script>
<custom-element-with-settable-only-property prop="8"></custom-element-with-settable-only-property>
Loading…
Cancel
Save