mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
prevent double update (#86794)
This commit is contained in:
parent
c9d3fea9c5
commit
d797b0c6b7
2 changed files with 34 additions and 0 deletions
|
@ -146,6 +146,35 @@ describe('ExpressionRenderer', () => {
|
|||
instance.unmount();
|
||||
});
|
||||
|
||||
it('should not update twice immediately after rendering', () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const refreshSubject = new Subject();
|
||||
const loaderUpdate = jest.fn();
|
||||
|
||||
(ExpressionLoader as jest.Mock).mockImplementation(() => {
|
||||
return {
|
||||
render$: new Subject(),
|
||||
data$: new Subject(),
|
||||
loading$: new Subject(),
|
||||
update: loaderUpdate,
|
||||
destroy: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const instance = mount(
|
||||
<ReactExpressionRenderer reload$={refreshSubject} expression="" debounce={1000} />
|
||||
);
|
||||
|
||||
act(() => {
|
||||
jest.runAllTimers();
|
||||
});
|
||||
|
||||
expect(loaderUpdate).toHaveBeenCalledTimes(1);
|
||||
|
||||
instance.unmount();
|
||||
});
|
||||
|
||||
it('waits for debounce period on other loader option change if specified', () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
|
|
|
@ -91,7 +91,12 @@ export const ReactExpressionRenderer = ({
|
|||
);
|
||||
const [debouncedExpression, setDebouncedExpression] = useState(expression);
|
||||
const [waitingForDebounceToComplete, setDebouncePending] = useState(false);
|
||||
const firstRender = useRef(true);
|
||||
useShallowCompareEffect(() => {
|
||||
if (firstRender.current) {
|
||||
firstRender.current = false;
|
||||
return;
|
||||
}
|
||||
if (debounce === undefined) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue