Skip to content

Commit 7eb87b7

Browse files
Fix href not being unset on nulish value (#2693)
1 parent 9fc5910 commit 7eb87b7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/diff/props.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
116116
name !== 'type' &&
117117
name !== 'size' &&
118118
name !== 'download' &&
119+
name !== 'href' &&
119120
!isSvg &&
120121
name in dom
121122
) {

test/browser/render.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,24 @@ describe('render()', () => {
457457
expect(scratch.innerHTML).to.equal('<input type="password">');
458458
});
459459

460+
it('should unset href if null || undefined', () => {
461+
render(
462+
<pre>
463+
<a href="#">href="#"</a>
464+
<a href={undefined}>href="undefined"</a>
465+
<a href={null}>href="null"</a>
466+
<a href={''}>href="''"</a>
467+
</pre>,
468+
scratch
469+
);
470+
471+
const links = scratch.querySelectorAll('a');
472+
expect(links[0].hasAttribute('href')).to.equal(true);
473+
expect(links[1].hasAttribute('href')).to.equal(false);
474+
expect(links[2].hasAttribute('href')).to.equal(false);
475+
expect(links[3].hasAttribute('href')).to.equal(true);
476+
});
477+
460478
describe('dangerouslySetInnerHTML', () => {
461479
it('should support dangerouslySetInnerHTML', () => {
462480
let html = '<b>foo &amp; bar</b>';

0 commit comments

Comments
 (0)