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

TextField / Select wrong render when props changed fast #216

Closed
Wroud opened this issue Apr 20, 2018 · 7 comments
Closed

TextField / Select wrong render when props changed fast #216

Wroud opened this issue Apr 20, 2018 · 7 comments

Comments

@Wroud
Copy link

Wroud commented Apr 20, 2018

What RMWC Version are you using?

checked on 1.4.1 and 1.5.5

What browser(s) and React Version is this bug affecting?

Google Chrome 66.0.3359.117, React 16.3.1

What are the steps to reproduce the bug?

Edit RMWC Sandbox

play with setTimeout delay & spam TEST button for reproducing bug

Any other information you believe would be useful?

Seems like bug depends of fields count and how fast render occurs
Also if props disabled=false but rendered as disabled=true in react-devtools set prop to true
class on div will be mdc-text-field--upgraded mdc-text-field--disabled mdc-text-field mdc-text-field--upgraded mdc-text-field--disabled

its like wrong class appending after props changed
also after textfield rendered div has class="mdc-text-field--upgraded mdc-text-field mdc-text-field--upgraded" why mdc-text-field--upgraded appended two times? its same bug?

@jamesmfriedman
Copy link
Collaborator

This is a really interesting bug. While React is responsible for rendering the markup, a lot of the work is delegated to the MDC code. There is definitely a communication issue somewhere in there.

Definitely something that I'll look into, but curious if it's blocking you right now, trying to figure out where to prioritize this one.

@Wroud
Copy link
Author

Wroud commented Apr 20, 2018

it's not blocking me, im added 100ms delay in my saga as temporary fix

@Wroud
Copy link
Author

Wroud commented Apr 20, 2018

checked code, look at this line
and this one
i think solution may be

export const addClass = () =>
  function(className: string) {
    if (!this.state.classes.has(className)) {
      this._safeSetState(prevState => {
        if(prevState.classes.has(className)) {
          return null;
        }
        return classes: prevState.classes.add(className)
      });
    }
  };

export const removeClass = () =>
  function(className: string) {
    if (this.state.classes.has(className)) {
      this._safeSetState(prevState => {
        if(!prevState.classes.has(className)) {
          return null;
        }
        return classes: prevState.classes.delete(className) ?
          prevState.classes :
          prevState.classes
      });
    }
  };

@jamesmfriedman
Copy link
Collaborator

Thanks! Thats a huge help. I think I know a way around this, I'll look into it.

@rjdestigter
Copy link

rjdestigter commented Apr 21, 2018

@jamesmfriedman Is this maybe related? https://codesandbox.io/s/62040p3mw

Basically, for the TextField component, when the value prop changes to undefined it does not clear the input. I resolved this by sending in an empty string if the value is undefined or null but that renders the TextField in a state of invalidity even though it hasn't had focus yet.

If not I can create an issue for this separately.

@jamesmfriedman
Copy link
Collaborator

Fixed in 1.5.6, please verify in your codebases.

@Wroud
Copy link
Author

Wroud commented Apr 23, 2018

It's seems fixed now, but i think you need move if statement in ._safeSetState((prevState)=> {here}) because this.state and prevState can be different

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants