-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Use setAttribute, not properties to fix SVG update #279
Conversation
This causes a regression in the TextField demo — try typing in the first field then the second field on both |
I've introduced a new |
Co-authored-by: Jed Fox <git@jedfox.com>
Is the |
IDK, I wasn't able to find any information on this other than some people warning that |
I think it’s usually based on specific names. Here’s React’s file that defines how it handles attributes and properties: https://github.com/facebook/react/blob/92c7e49895032885cffaad77a69d71268dda762e/packages/react-dom/src/shared/DOMProperty.js Here’s how it’s used for updating DOM nodes: https://github.com/facebook/react/blob/92c7e49895032885cffaad77a69d71268dda762e/packages/react-dom/src/client/DOMPropertyOperations.js#L129-L206 |
Interesting that // These are the few React props that we set as DOM properties
// rather than attributes. These are all booleans.
[
'checked',
// Note: `option.selected` is not updated if `select.multiple` is
// disabled with `removeAttribute`. We have special logic for handling this.
'multiple',
'muted',
'selected', |
If its a set list, could we just automatically check them instead of each element specifying if it needs to be treated as a property? |
I thought about it, but attributes are created everywhere on every render cycle, which means that the check is multiplied by the number of times you use any attribute whatsoever. I'm not sure what's the best way to avoid the check on attribute creation other than hardcoding it as a property at the place of use. |
Another option would be to forbid attribute creation from a string literal and predefine all attributes in |
You could do it with type-safety and allow a string literal: struct HTMLAttribute : ExpressibleByStringLiteral {
...
static let value: Self = .init("value", isUpdatedAsProperty: true)
} Something like that? |
Yeah, it wouldn't prevent anyone from still initializing |
Could make it more explicit with a |
Oh, requiring |
it looks like there are a bunch of files in |
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.
Either way I think this is a good start to unblock our user, and we can iterate more later.
Property assignment does not update SVG elements. We may want to use properties instead of
setAttribute
in the future for optimizations. For now I think thatsetAttribute
works in all cases, including SVG, and seems safer to me.Resolves #278.