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

Avoid setting value for progress with nullish value #4492

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ function diffElementNodes(
// As above, don't diff props during hydration
if (!isHydrating) {
i = 'value';
if (
if (nodeType === 'progress' && inputValue == null) {
dom.removeAttribute('value');
} else if (
inputValue !== undefined &&
// #2756 For the <progress>-element the initial value is 0,
// despite the attribute not being present. When the attribute
Expand Down
14 changes: 14 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,20 @@ 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={50} />, scratch);
expect(scratch.firstChild.getAttribute('value')).to.equal('50');
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
Loading