Skip to content
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

Pass all SVG attributes through #5714

Merged
merged 4 commits into from
Dec 25, 2015
Merged

Pass all SVG attributes through #5714

merged 4 commits into from
Dec 25, 2015

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Dec 22, 2015

Update: this was reverted in favor of a different approach in #6243.

If any attribute is missing please file an issue and we'll add it.


All attributes defined on SVG elements will now be passed directly regardless of the whitelist.
The casing specified by user will be preserved, and setAttribute() will be used.

In the future we will remove support for the camel case aliases to the hyphenated attributes. For example, we currently map strokeWidth to stroke-width but this is now deprecated behind a warning. When we remove support for this, we can remove some of the code paths introduced in this commit.

The purpose of this change is to stop maintaining a separate SVG property config.
The config still exists for two purposes:

  • Allow a migration path for deprecated camelcased versions of hyphenated SVG attributes
  • Track special namespaced attributes (they still require a whitelist)

However it is no longer a blocker for using new non-namespaced SVG attributes, and users don't have to ask us to add them to the whitelist.

Fixes #1657

Reviewers: @spicyj @jimfb @sebmarkbage

@sophiebits
Copy link
Collaborator

This seems good.

  • Can we make the warning here SVG-specific? Maybe "SVG attribute clipPath is deprecated; use the original attribute name clip-path for SVG tags instead."
  • Instead of a new "deprecated" flag, can we just compare the attribute name in createMarkupForSVGAttribute and warn if it's different (and there's no namespace)? If I'm missing some reason that won't work, this way is fine too.

I thought I had a third thing too but I forget now.

@@ -29,6 +29,7 @@ var DOMPropertyInjection = {
HAS_NUMERIC_VALUE: 0x10,
HAS_POSITIVE_NUMERIC_VALUE: 0x20 | 0x10,
HAS_OVERLOADED_BOOLEAN_VALUE: 0x40,
IS_DEPRECATED_PROPERTY: 0x100,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep this, it should be 0x80.

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 23, 2015

Amended the commit based on your comments. I added a completely separate code path for the SVG warning so it's easy to remove later and we don't have to think about getPossibleStandardName being broken in this case.

@facebook-github-bot
Copy link

@gaearon updated the pull request.

@facebook-github-bot
Copy link

@gaearon updated the pull request.

@gaearon gaearon changed the title [WIP] Pass all SVG attributes through Pass all SVG attributes through Dec 23, 2015
@gaearon
Copy link
Collaborator Author

gaearon commented Dec 23, 2015

I updated the PR with what I believe to be the complete implementation, but I haven't tested it in the wild yet. Does it look good to go otherwise?

@facebook-github-bot
Copy link

@gaearon updated the pull request.

1 similar comment
@facebook-github-bot
Copy link

@gaearon updated the pull request.

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 23, 2015

One thing that concerned me is whether I should add new DOMPropertyOperations methods to

ReactPerf.measureMethods(DOMPropertyOperations, 'DOMPropertyOperations', {
  setValueForProperty: 'setValueForProperty',
  setValueForAttribute: 'setValueForAttribute',
  deleteValueForProperty: 'deleteValueForProperty',
});

at the bottom.

return '';
}
var propertyInfo = DOMProperty.properties.hasOwnProperty(name) ?
DOMProperty.properties[name] : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 2 space indent (you have a couple of this exact 2 lines doing the same thing - maybe have a helper method?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to follow the existing style in this file.

Here are a few places I haven't touched where indentation is the same as mine, and they also don't bother to extract the helper function:

https://github.com/gaearon/react/blob/013340a44dbf99e5855962e68688453eab324f5f/src/renderers/dom/shared/DOMPropertyOperations.js#L159-L160

https://github.com/gaearon/react/blob/013340a44dbf99e5855962e68688453eab324f5f/src/renderers/dom/shared/DOMPropertyOperations.js#L229-L230

https://github.com/gaearon/react/blob/013340a44dbf99e5855962e68688453eab324f5f/src/renderers/dom/shared/DOMPropertyOperations.js#L302-L303

I'm happy to re-indent all of them at once and add a helper for getting the property, if you'd like! Just wanted to avoid introducing inconsistencies. Also I didn't want to overgeneralize because this code will later be likely removed when we kill the deprecation path and just start treating SVG pretty much like custom components.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's just leave it as is then 👍

This was referenced Dec 23, 2015
All attributes defined on SVG elements will now be passed directly regardless of the whitelist. The casing specified by user will be preserved, and setAttribute() will be used.

In the future we will remove support for the camel case aliases to the hyphenated attributes. For example, we currently map `strokeWidth` to `stroke-width` but this is now deprecated behind a warning. When we remove support for this we can remove some of the code paths introduced in this commit.

The purpose of this change is to stop maintaining a separate SVG property config. The config still exists for two purposes:

* Allow a migration path for deprecated camelcased versions of hyphenated SVG attributes
* Track special namespaced attributes (they still require a whitelist)

However it is no longer a blocker for using new non-namespaced SVG attributes, and users don't have to ask us to add them to the whitelist.

Fixes #1657
@facebook-github-bot
Copy link

@gaearon updated the pull request.

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 24, 2015

I updated the PR to merge cleanly on top of #5590 but unlike #5590 it still uses the old warning system.
I'll look into updating this PR to use devtool but this can be done separately.

In #5590 a new system was introduced for tracking dev-time warnings.
This commit uses it for reporting SVG attribute deprecation warnings.
@gaearon
Copy link
Collaborator Author

gaearon commented Dec 24, 2015

I moved the warnings into a separate devtool to align with #5590.
I'm adding @jimfb to reviewers so he can evaluate whether I'm using it correctly.

@facebook-github-bot
Copy link

@gaearon updated the pull request.

@@ -862,6 +864,11 @@ ReactDOMComponent.Mixin = {
DOMProperty.properties[propKey] ||
DOMProperty.isCustomAttribute(propKey)) {
DOMPropertyOperations.deleteValueForProperty(getNode(this), propKey);
} else if (this._namespaceURI === DOMNamespaces.svg) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean for this to be above the previous case? I think it works out the same either way, so I guess it doesn't really matter.

gaearon added a commit that referenced this pull request Dec 26, 2015
@kumarharsh
Copy link

I see that this change is not in the 0.14.x branch. Will this be backported?

@zpao
Copy link
Member

zpao commented Mar 9, 2016

No this will not be backported.

zpao added a commit to zpao/react that referenced this pull request Mar 9, 2016
…-attributes"

This reverts commit 53dabe7, reversing
changes made to 82fe64a.
zpao added a commit to zpao/react that referenced this pull request Mar 11, 2016
…-attributes"

This reverts commit 53dabe7, reversing
changes made to 82fe64a.
@SimenB
Copy link
Contributor

SimenB commented Dec 11, 2016

This was reverted, so could the OP be updated to reflect that? Lots of issues for SVG point to this one, it confused me before more googling led me to #6243

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 11, 2016

Updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants