preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
949 stars 148 forks source link

should not change input value when changing "defaultValue" attr. #445

Open jo32 opened 6 years ago

jo32 commented 6 years ago

react: https://jsfiddle.net/jo32/85fgabqy/

vs

preact-compat: https://jsfiddle.net/jo32/0gzo34u6/

gavar commented 6 years ago

I can confirm the issue exists on version 3.18.4

Lines of code affecting it: https://github.com/developit/preact-compat/blob/3.18.4/src/index.js#L96-L101

You could temporary solve this problem by inverting logic after rendering, by calling this function on the react element:

function fixDefaultValueBug(element, props) {
  const {value, defaultValue} = props;
  if (defaultValue) {
    if (!value && value !== 0) {
      delete element.props.value;
      element.props.defaultValue = defaultValue;
    }
  }
}