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

respect default value #4341

Merged
merged 7 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ function diffElementNodes(
} else if (i == 'dangerouslySetInnerHTML') {
oldHtml = value;
} else if (i !== 'key' && !(i in newProps)) {
if (i == 'value' && 'defaultValue' in newProps) continue;
setProperty(dom, i, null, value, isSvg);
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/browser/hydrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ describe('hydrate()', () => {
teardown(scratch);
});

// Test for preactjs/preact#4340
it('should respect defaultValue in hydrate', () => {
scratch.innerHTML = '<input value="foo">';
hydrate(<input defaultValue="foo" />, scratch);
expect(scratch.firstChild.value).to.equal('foo');
});
JoviDeCroock marked this conversation as resolved.
Show resolved Hide resolved

it('should reuse existing DOM', () => {
const onClickSpy = sinon.spy();
const html = ul([li('1'), li('2'), li('3')]);
Expand Down
16 changes: 16 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ describe('render()', () => {
expect(scratch.firstChild.spellcheck).to.equal(false);
});

// Test for preactjs/preact#4340
it('should respect defaultValue in render', () => {
scratch.innerHTML = '<input value="foo">';
render(<input defaultValue="foo" />, scratch);
expect(scratch.firstChild.value).to.equal('foo');
});

// Test for preactjs/preact#4340
it('should support subsequent renders', () => {
scratch.innerHTML = '<input value="foo">';
render(<input defaultValue="foo" value="bar" />, scratch);
expect(scratch.firstChild.value).to.equal('bar');
render(<input defaultValue="foo" value="baz" />, scratch);
expect(scratch.firstChild.value).to.equal('baz');
});

it('should render download attribute', () => {
render(<a download="" />, scratch);
expect(scratch.firstChild.getAttribute('download')).to.equal('');
Expand Down
Loading