-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Attempt to set read-only props using attr. #2808
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
Conversation
|
It looks like this might also be relevant to #1708. |
I'm not sure what should happen here in light of #3013. Do we want to switch to using |
maybe? Presumably that would prevent issues like this, but result in incorrect behaviour in cases where the prop isn't controlled by the attribute ( <input {...objectThatIncludesAKeyNamedValue} value={objectThatIncludesAKeyNamedValue.value}> ...whereas you can't really work around this issue. Man, SVG is terrible. |
Agreed, SVG & this props/attributes duality is lame. Here's a workaround that uses a reactive block: let dom__svg
let props
$: props = unpick($$props, 'class')
$: {
props
dom__svg && each(keys(props),
prop => dom__svg.setAttribute(prop, props[prop]))
} |
How about per-component node attribute setter? <svelte:options forceNodeAttributes={{'tagName' :['viewBox', 'width', 'height' ]}} /> <!-- Or any better prop name --> // runtime/internal/dom.ts
function set_attributes(node, props, forceAttributes) { // forceNodeAttributes[node.tag]
for (const key in props) {
if (key === 'style') {
node.style.cssText = props[key];
} else if (forceAttributes && key in forceAttributes) {
attr(node, key, props[key]);
} else if (key in node) { // Own property
node[key] = props[key];
} else {
attr(node, key, props[key]);
}
}
} Or <svelte:options setter={(node, attributes) => { // Do something }} /> |
#1708 has an interesting idea, of checking |
Closing: See #3531. |
Fixes #2732
I have not found a way to reliably reflect on the property, but
try/catch
seems to do the trick.