preact icon indicating copy to clipboard operation
preact copied to clipboard

Simplify compat defaultValue handling

Open andrewiggins opened this issue 4 years ago • 5 comments

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.

coverage.zip

andrewiggins avatar Jul 01 '20 06:07 andrewiggins

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

compressed-size-action

github-actions[bot] avatar Jul 01 '20 06:07 github-actions[bot]

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.

andrewiggins avatar Jul 01 '20 06:07 andrewiggins

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
  • HTMLSelectElement
    • No defaultValue or defaultSelected in DOM
    • React does support defaultValue with arrays on <select>
  • HTMLOptionElement
    • TODO: Check out defaultSelected in DOM
    • TODO: check if React supports defaultValue here or if its defaultSelected behavior differs from DOM
  • HTMLButtonElement
    • no defaultValue in DOM
    • TODO: Need to check React
  • HTMLProgressElement
    • no defaultValue in DOM
    • TODO: Need to check React

andrewiggins avatar Jul 01 '20 06:07 andrewiggins

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?

monaye avatar Jul 13 '20 16:07 monaye

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.

andrewiggins avatar Jul 13 '20 19:07 andrewiggins