Skip to content

Commit

Permalink
Merge pull request #2763 from preactjs/revert-2734-patch-1
Browse files Browse the repository at this point in the history
Revert "Fix rendering an SVG-element with xmlns:xlink-prop"
  • Loading branch information
marvinhagemeister authored Sep 22, 2020
2 parents 134f65c + cf3c60e commit 0c14a92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
20 changes: 10 additions & 10 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
) {
dom[name] = value == null ? '' : value;
} else if (typeof value != 'function' && name !== 'dangerouslySetInnerHTML') {
const oldName = name;
if (name !== (name = name.replace(/^(xlink|xmlns):?/, ''))) {
let ns =
'http://www.w3.org/' +
(/xm/.test(oldName) ? '2000/xmlns/' : '1999/xlink');
if (/xm/.test(oldName)) {
name = oldName === 'xmlns' ? oldName : 'xmlns:' + name;
}
if (name !== (name = name.replace(/xlink:?/, ''))) {
if (value == null || value === false) {
dom.removeAttributeNS(ns, name.toLowerCase());
dom.removeAttributeNS(
'http://www.w3.org/1999/xlink',
name.toLowerCase()
);
} else {
dom.setAttributeNS(ns, name.toLowerCase(), value);
dom.setAttributeNS(
'http://www.w3.org/1999/xlink',
name.toLowerCase(),
value
);
}
} else if (
value == null ||
Expand Down
11 changes: 5 additions & 6 deletions test/browser/svg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ describe('svg', () => {

it('should support svg attributes', () => {
const Demo = ({ url }) => (
<svg
viewBox="0 0 360 360"
xlinkHref={url}
xmlnsXlink="http://www.w3.org/1999/xlink"
>
<svg viewBox="0 0 360 360" xlinkHref={url}>
<path
d="M 347.1 357.9 L 183.3 256.5 L 13 357.9 V 1.7 h 334.1 v 356.2 Z M 58.5 47.2 v 231.4 l 124.8 -74.1 l 118.3 72.8 V 47.2 H 58.5 Z"
fill="black"
Expand All @@ -63,10 +59,13 @@ describe('svg', () => {
' xmlns="http://www.w3.org/2000/svg"',
''
);
html = sortAttributes(
html.replace(' xmlns:xlink="http://www.w3.org/1999/xlink"', '')
);
expect(html).to.equal(
sortAttributes(
`
<svg viewBox="0 0 360 360" xlink:href="www.preact.com" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg viewBox="0 0 360 360" xlink:href="www.preact.com">
<path d="M 347.1 357.9 L 183.3 256.5 L 13 357.9 V 1.7 h 334.1 v 356.2 Z M 58.5 47.2 v 231.4 l 124.8 -74.1 l 118.3 72.8 V 47.2 H 58.5 Z" fill="black" stroke="white"></path>
</svg>
`.replace(/[\n\t]+/g, '')
Expand Down

0 comments on commit 0c14a92

Please sign in to comment.