From 759a2b64f3db831b08ccf2d8e9390af15f2cf16f Mon Sep 17 00:00:00 2001 From: Matt Bargar Date: Wed, 7 Nov 2018 11:18:43 -0500 Subject: [PATCH] Add hacky workaround for getDerivedStateFromProps change in react 16.4 (#25142) (#25245) --- src/ui/public/query_bar/components/query_bar.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/public/query_bar/components/query_bar.tsx b/src/ui/public/query_bar/components/query_bar.tsx index 455e05cb1dea..4b8b6d207340 100644 --- a/src/ui/public/query_bar/components/query_bar.tsx +++ b/src/ui/public/query_bar/components/query_bar.tsx @@ -23,7 +23,7 @@ declare module '@elastic/eui' { export const EuiOutsideClickDetector: SFC; } -import { debounce } from 'lodash'; +import { debounce, isEqual } from 'lodash'; import React, { Component, SFC } from 'react'; import { getFromLegacyIndexPattern } from 'ui/index_patterns/static_utils'; import { kfetch } from 'ui/kfetch'; @@ -84,16 +84,22 @@ interface State { index: number | null; suggestions: AutocompleteSuggestion[]; suggestionLimit: number; + currentProps?: Props; } export class QueryBar extends Component { public static getDerivedStateFromProps(nextProps: Props, prevState: State) { + if (isEqual(prevState.currentProps, nextProps)) { + return null; + } + if (nextProps.query.query !== prevState.query.query) { return { query: { query: toUser(nextProps.query.query), language: nextProps.query.language, }, + currentProps: nextProps, }; } else if (nextProps.query.language !== prevState.query.language) { return { @@ -101,6 +107,7 @@ export class QueryBar extends Component { query: '', language: nextProps.query.language, }, + currentProps: nextProps, }; }