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 1 commit
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
2 changes: 2 additions & 0 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
} 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 Expand Up @@ -524,6 +525,7 @@
// again, which triggers IE11 to re-evaluate the select value
(nodeType === 'option' && inputValue !== oldProps[i]))
) {
console.log('setting', i);

Check warning on line 528 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test

Unexpected console statement

Check warning on line 528 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test / Build & Test

Unexpected console statement
JoviDeCroock marked this conversation as resolved.
Show resolved Hide resolved
setProperty(dom, i, inputValue, oldProps[i], false);
}

Expand Down
6 changes: 6 additions & 0 deletions test/browser/hydrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ describe('hydrate()', () => {
teardown(scratch);
});

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
9 changes: 8 additions & 1 deletion test/browser/render.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setupRerender } from 'preact/test-utils';
import { createElement, render, Component, options } from 'preact';
import { createElement, render, Component, options, hydrate } from 'preact';
JoviDeCroock marked this conversation as resolved.
Show resolved Hide resolved
import {
setupScratch,
teardown,
Expand Down Expand Up @@ -472,6 +472,13 @@ describe('render()', () => {
expect(scratch.firstChild.spellcheck).to.equal(false);
});

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

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