-
Notifications
You must be signed in to change notification settings - Fork 559
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
Refactor: Replace search field focus state with middleware #1914
Refactor: Replace search field focus state with middleware #1914
Conversation
Alternative idea to #1908 `searchFocus` isn't quite app state. We have been using it as a workaround in order to trigger side-effects from Redux in order to focus the search field. In this patch we're removing that state altogether and replacing it with a custom middleware specific to the search field. This too is somewhat ugly because of the coupling between the middleware and the search field component; it needs more thought on how best to register the DOM node containing focus. Nevertheless by removing the `state` property we are able to remove more code and the update loop that was necessary to set focus, update, an then record that the focus was already set or unset. Storing a state value for focus doesn't match the reality that the focus is a property of the DOM node and changes independently from the Redux actions being dispatched in the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. It's less of a hack than the existing code (or my PR), works fine, and incidentally fixes a minor interaction bug (after selecting a suggested tag, the cursor is placed in the search field, but the text is now not selected, which is as it should be IMO).
@@ -18,20 +18,33 @@ export class SearchField extends Component<ConnectedProps> { | |||
|
|||
inputField = createRef<HTMLInputElement>(); | |||
|
|||
componentDidUpdate() { | |||
const { searchFocus, onSearchFocused } = this.props; | |||
componentDidMount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are making a mistake adding more componentDidMounts to the app, at very least this should be: UNSAFE_componentWillMount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, let's merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad DidMount is fine.
Alternative idea to #1908
searchFocus
isn't quite app state. We have been using it as aworkaround in order to trigger side-effects from Redux in order
to focus the search field.
In this patch we're removing that state altogether and replacing
it with a custom middleware specific to the search field. This too
is somewhat ugly because of the coupling between the middleware
and the search field component; it needs more thought on how best
to register the DOM node containing focus.
Nevertheless by removing the
state
property we are able to removemore code and the update loop that was necessary to set focus,
update, an then record that the focus was already set or unset.
Storing a state value for focus doesn't match the reality that the
focus is a property of the DOM node and changes independently from
the Redux actions being dispatched in the app.