preact
preact copied to clipboard
Simplify compat defaultValue handling
The code removed below was originally added back in preactjs/preact-compat#280. However, in a recent change (maybe #2392?) the props.value = props.defaultValue
stopped being covered by our tests (see attached). So I wondered if this code was even necessary anymore. I added some additional tests to try and push the boundary of whether this code is needed. Seems like it isn't and we can rely on native defaultValue handling. MDN seems to imply defaultValue works going back a while (though I did find one bug with textarea and defaultValue in IE11)
I also adding a warning when using preact/compat and value
and defaultValue
on an input
tag. React warns about this and figured it would be good if we did too. The benefit is to push people to use preact/compat with only React-approved patterns to limit the scope of what preact/compat needs to support. I don't want to support unsupported React behaviors in preact/compat too lol.
Size Change: +246 B (0%)
Total Size: 40.3 kB
Filename | Size | Change | |
---|---|---|---|
compat/dist/compat.js |
3.19 kB | -10 B (0%) | |
compat/dist/compat.module.js |
3.21 kB | -13 B (0%) | |
compat/dist/compat.umd.js |
3.24 kB | -13 B (0%) | |
debug/dist/debug.js |
3.09 kB | +93 B (3%) | |
debug/dist/debug.module.js |
3.08 kB | +96 B (3%) | |
debug/dist/debug.umd.js |
3.17 kB | +93 B (2%) |
ℹ️ View Unchanged
Filename | Size | Change | |
---|---|---|---|
devtools/dist/devtools.js |
184 B | 0 B | |
devtools/dist/devtools.module.js |
195 B | 0 B | |
devtools/dist/devtools.umd.js |
260 B | 0 B | |
dist/preact.js |
3.96 kB | 0 B | |
dist/preact.min.js |
3.98 kB | 0 B | |
dist/preact.module.js |
3.97 kB | 0 B | |
dist/preact.umd.js |
4.01 kB | 0 B | |
hooks/dist/hooks.js |
1.09 kB | 0 B | |
hooks/dist/hooks.module.js |
1.11 kB | 0 B | |
hooks/dist/hooks.umd.js |
1.17 kB | 0 B | |
test-utils/dist/testUtils.js |
437 B | 0 B | |
test-utils/dist/testUtils.module.js |
439 B | 0 B | |
test-utils/dist/testUtils.umd.js |
515 B | 0 B |
To be clear, it could also be the case that we are missing some tests, so if you think this is still needed, let's add some tests to justify its existence.
Okay, this is probably a terrible idea. Already found one failing test. Should probably understand how defaultValue does (or does not) affect these other form elements:
-
HTMLInputElement
- TODO: Checkout
defaultChecked
in DOM - TODO: Understand if React's
defaultChecked
behavior differs from DOM
- TODO: Checkout
-
HTMLSelectElement
- No
defaultValue
ordefaultSelected
in DOM - React does support
defaultValue
with arrays on<select>
- No
-
HTMLOptionElement
- TODO: Check out
defaultSelected
in DOM - TODO: check if React supports defaultValue here or if its defaultSelected behavior differs from DOM
- TODO: Check out
-
HTMLButtonElement
- no defaultValue in DOM
- TODO: Need to check React
-
HTMLProgressElement
- no defaultValue in DOM
- TODO: Need to check React
though I did find one bug with textarea and defaultValue in IE11
@andrewiggins I think I am seeing this issue. Do you know if this had been fixed or do we have an issue open for this?
Hey @monaye, I don't think we have an issue that particular thing yet. Could you go ahead and open a new one describing the issue you are running into? That way others on the team can jump on and perhaps we can come up with a quick fix for you.