diff --git a/CHANGELOG.md b/CHANGELOG.md index c952a9f2635..217e063d94f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixed `EuiKeyPadMenu` and `EuiKeyPadMenuItem` aria roles ([#3502](https://github.com/elastic/eui/pull/3502)) - Fixed `EuiFieldSearch` input clear button doesn't show when external input is passed([#3497](https://github.com/elastic/eui/pull/3497)) - Fixed `EuiBasicTable` footers to always use a unique `key` ([#3559](https://github.com/elastic/eui/pull/3559)) +- Fixed `EuiInMemoryTable` by changing the `getDerivedStateFromProps` to not block the updates as soon as it hits a true if condition ([#3579](https://github.com/elastic/eui/pull/3579)) **Breaking changes** diff --git a/src/components/basic_table/in_memory_table.tsx b/src/components/basic_table/in_memory_table.tsx index dfb90e51b6d..058ebd2162d 100644 --- a/src/components/basic_table/in_memory_table.tsx +++ b/src/components/basic_table/in_memory_table.tsx @@ -246,11 +246,15 @@ export class EuiInMemoryTable extends Component< nextProps: EuiInMemoryTableProps, prevState: State ) { + let updatedPrevState = prevState; + let componentShouldUpdate = false; if (nextProps.items !== prevState.prevProps.items) { // We have new items because an external search has completed, so reset pagination state. - return { + componentShouldUpdate = true; + updatedPrevState = { + ...updatedPrevState, prevProps: { - ...prevState.prevProps, + ...updatedPrevState.prevProps, items: nextProps.items, }, pageIndex: 0, @@ -264,7 +268,9 @@ export class EuiInMemoryTable extends Component< sortName !== prevState.prevProps.sortName || sortDirection !== prevState.prevProps.sortDirection ) { - return { + componentShouldUpdate = true; + updatedPrevState = { + ...updatedPrevState, sortName, sortDirection, }; @@ -278,15 +284,19 @@ export class EuiInMemoryTable extends Component< : ''; if (nextQuery !== prevQuery) { - return { + componentShouldUpdate = true; + updatedPrevState = { + ...updatedPrevState, prevProps: { - ...prevState.prevProps, + ...updatedPrevState.prevProps, search: nextProps.search, }, query: getQueryFromSearch(nextProps.search, false), }; } - + if (componentShouldUpdate) { + return updatedPrevState; + } return null; }