@@ -13,16 +13,28 @@ import { injectIntl } from "renderer/hocs/injectIntl";
1313class SearchControl extends React . PureComponent < Props , State > {
1414 override state : State = { value : this . props . search ?? "" } ;
1515
16+ // values we wrote whose location update hasn't come back yet, oldest first
17+ inFlight : string [ ] = [ ] ;
18+
1619 override componentDidUpdate ( prevProps : Props ) {
20+ const search = this . props . search ?? "" ;
21+ if ( ( prevProps . search ?? "" ) === search ) {
22+ return ;
23+ }
24+ // our own write coming back: the input may already be ahead of it, so
25+ // it must not be reset to this older value
26+ const echoed = this . inFlight . indexOf ( search ) ;
27+ if ( echoed >= 0 ) {
28+ this . inFlight . splice ( 0 , echoed + 1 ) ;
29+ return ;
30+ }
1731 // the page can change the search from outside (clicking a channel on
1832 // the builds page does this), cancel any pending debounced write so it
1933 // doesn't overwrite the new value
20- if (
21- prevProps . search !== this . props . search &&
22- this . props . search !== this . state . value
23- ) {
34+ this . inFlight = [ ] ;
35+ if ( search !== this . state . value ) {
2436 this . setSearch . cancel ( ) ;
25- this . setState ( { value : this . props . search ?? "" } ) ;
37+ this . setState ( { value : search } ) ;
2638 }
2739 }
2840
@@ -53,6 +65,9 @@ class SearchControl extends React.PureComponent<Props, State> {
5365 // tab hasn't derived a location yet, nothing to evolve
5466 return ;
5567 }
68+ if ( search !== ( this . props . search ?? "" ) ) {
69+ this . inFlight . push ( search ) ;
70+ }
5671 dispatchTabEvolve ( this . props , {
5772 replace : true ,
5873 url : urlWithParams ( url , { search } ) ,
0 commit comments