Skip to content

Commit 202fdf2

Browse files
committed
Replay the request to avoid subscription races
The subscription timing is slightly unpredictable due to React's effect execution order. This way initial requests won't get lost. The response$ is multicast already due to `share()`, so I don't expect any negative consequences. (famous last words)
1 parent d5f7e1e commit 202fdf2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

x-pack/plugins/infra/public/utils/data_search/use_data_search_request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { useCallback } from 'react';
9-
import { OperatorFunction, Subject } from 'rxjs';
9+
import { OperatorFunction, ReplaySubject } from 'rxjs';
1010
import { share, tap } from 'rxjs/operators';
1111
import {
1212
IKibanaSearchRequest,
@@ -47,7 +47,7 @@ export const useDataSearch = <
4747
}) => {
4848
const { services } = useKibanaContextForPlugin();
4949
const requests$ = useObservable(
50-
() => new Subject<ParsedDataSearchRequestDescriptor<Request, Response>>(),
50+
() => new ReplaySubject<ParsedDataSearchRequestDescriptor<Request, Response>>(1),
5151
[]
5252
);
5353

0 commit comments

Comments
 (0)