Skip to content

Commit

Permalink
Avoid setting value for progress with nullish value
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Sep 12, 2024
1 parent 022dbb1 commit c7b6ea3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,16 @@ function diffElementNodes(
// despite the attribute not being present. When the attribute
// is missing the progress bar is treated as indeterminate.
// To fix that we'll always update it when it is 0 for progress elements
(inputValue !== dom[i] ||
(nodeType === 'progress' && !inputValue) ||
((inputValue !== dom[i] && nodeType !== 'progress') ||
(nodeType === 'progress' && inputValue === 0) ||
// This is only for IE 11 to fix <select> value not being updated.
// To avoid a stale select value we need to set the option.value
// again, which triggers IE11 to re-evaluate the select value
(nodeType === 'option' && inputValue !== oldProps[i]))
) {
setProperty(dom, i, inputValue, oldProps[i], namespace);
} else if (nodeType === 'progress' && inputValue == null) {
dom.removeAttribute('value');
}

i = 'checked';
Expand Down
12 changes: 12 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,18 @@ describe('render()', () => {
expect(scratch.firstChild.getAttribute('value')).to.equal('0');
});

// #4487
it('should not set value for undefined/null on a progress element', () => {
render(<progress value={undefined} />, scratch);
expect(scratch.firstChild.getAttribute('value')).to.equal(null);
render(<progress value={null} />, scratch);
expect(scratch.firstChild.getAttribute('value')).to.equal(null);
render(<progress value={0} />, scratch);
expect(scratch.firstChild.getAttribute('value')).to.equal('0');
render(<progress value={null} />, scratch);
expect(scratch.firstChild.getAttribute('value')).to.equal(null);
});

it('should always diff `checked` and `value` properties against the DOM', () => {
// See https://github.com/preactjs/preact/issues/1324

Expand Down

0 comments on commit c7b6ea3

Please sign in to comment.