-
Notifications
You must be signed in to change notification settings - Fork 148
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
Fixes issue where searchbar is not editable on chrome #140
Fixes issue where searchbar is not editable on chrome #140
Conversation
Codecov Report
@@ Coverage Diff @@
## master #140 +/- ##
==========================================
+ Coverage 53.13% 53.16% +0.03%
==========================================
Files 106 106
Lines 2650 2652 +2
Branches 273 274 +1
==========================================
+ Hits 1408 1410 +2
Misses 1213 1213
Partials 29 29
Continue to review full report at Codecov.
|
I think this may need some more work, I'm still getting an uneditable search bar at times. |
I would propose making |
This probably worth us officially stating somewhere, but the current code in this repo can reasonably be guaranteed to work in MacOS Chrome (what we develop on at Lyft, with functionality working as expected in production), so it's new to us that this bug exists. As a result in addition to updating code I'm curious to see if we can try to fully understand what is occurring differently in our environments. I unfortunately don't have a Linux machine to try this out on. The behavior I see when typing a single character into the SearchBar is as follows:
What do you observe in your environment? Are you perhaps seeing |
Yes, as per the docs, getDerivedStateFromProps is now called every time before render. This is the observed flow from console.log statements. You can see my keypresses in handleValueChange: handleValueChange: (event.target as HTMLInputElement).value=a |
There are other places too. When I edit the owners of a table, I see the edit box, but after clicking "Add" the list does not build up, so clicking Save saves nothing as the array is empty. Here are all places I found the static method, but I did not test them all: components/TableDetail/index.tsx |
Just updated the PR to use an empty string and only apply the props if state is not an empty string. This probably needs further discussion, as I'm not sure this is the right thing to do. |
It almost worked, but when everything is deleted (backspace), the value now reverts to the property setting, so you can't clear the search field entirely. Setting searchTerm to "null" didn't work for me because it failed the unit test. |
@gtoonstra Thanks for the extra information! Yes, Reference: https://reactjs.org/blog/2018/05/23/react-v-16-4.html#bugfix-for-getderivedstatefromprops The behavior of
The behavior of
Next Steps:
|
@ttannis : [email protected] /data/amundsen/amundsenfrontendlibrary/amundsen_application/static |
When I set searchTerm initialized to null, all unit tests broke because it seems to expect a string there. What I ended up doing was use another state variable to indicate if the state was changed by the user. That way, searchTerm doesn't have a magic value that changes the logic and the purpose is more explicit. Let me know what you think. There's at least another issue with the UI when editing the owners where a similar approach could be adopted. |
@gtoonstra Ah ha. So you are running at 5 minor versions above what we're currently developing for. React is set at 16.3.2 in our
|
I still get 16.8.6. I verified that package and package-lock are the versions as they exist on master. This looks like an issue of my ubuntu machine that I need to resolve myself. (npm uses version 3.5.2 and node 8.10.0). I'd recommend upgrading react with a local group of devs and look at it with fresh eyes on what the best way is to upgrade. So I'm in favor of closing this PR, I need to sort out my machine and if that doesn't work, I can use a modified version for the time being to make things work. |
Sounds good. If you encounter anymore problems or might want help sorting out your machine, feel free to reach out in our slack channel. Off the top of my head you should upgrade to at least npm 6.x.x. |
Summary of Changes
On Linux Chrome 74.0.3729.131 I was unable to edit anything in the search bar input field. I did some investigation and found that the "render" method in react always calls "getDerivedStateFromProps" before every render.
I inserted some console.log statements to confirm the flow of function calls and noticed that this was the case. The following page from react states useful things about unconditionally copying state from the props into the value:
https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html
Because of type checking I was unable to add another property to the state that was not already in props. So I opted for a simple searchTerm conditional check.
Recompiling and rerunning this on my computer gave me the ability to type text in there.
I'm by no means a web let alone a react developer, but this PR should serve as useful input to a discussion to fix this in a better way.
Tests
Checklist
I attempted to run "npm run lint", but that gave me errors:
Tried to lint /data/amundsen/amundsenfrontendlibrary/amundsen_application/static/jest.config.js but found no valid, enabled rules for this file type and file path in the resolved configuration.
Tried to lint /data/amundsen/amundsenfrontendlibrary/amundsen_application/static/coverage/lcov-report/prettify.js but found no valid, enabled rules for this file type and file path in the resolved configuration.
Tried to lint /data/amundsen/amundsenfrontendlibrary/amundsen_application/static/coverage/lcov-report/sorter.js but found no valid, enabled rules for this file type and file path in the resolved configuration.
Tried to lint /data/amundsen/amundsenfrontendlibrary/amundsen_application/static/dist/main.js but found no valid, enabled rules for this file type and file path in the resolved configuration.
Tried to lint /data/amundsen/amundsenfrontendlibrary/amundsen_application/static/dist/vendors.js but found no valid, enabled rules for this file type and file path in the resolved configuration.