diff --git a/src/plugins/layout/Inspector.js b/src/plugins/layout/Inspector.js index d36899f27..7faa68a38 100644 --- a/src/plugins/layout/Inspector.js +++ b/src/plugins/layout/Inspector.js @@ -109,14 +109,7 @@ export default class Inspector extends Component { const ids = nodes .map(n => [n.id, ...(n.children || [])]) .reduce((acc, cv) => acc.concat(cv), []); - this.getNodes(ids, {}).then(nodes => { - nodes.forEach(node => { - // Check if there are new IDs in the children array, and call getNodes() - // if there are any - const cIds = node.children.filter(c => !this.elements()[c]); - this.getNodes(cIds, {}); - }); - }); + this.invalidate(ids); }, ); @@ -166,6 +159,19 @@ export default class Inspector extends Component { } } + invalidate(ids: Array): Promise> { + if (ids.length === 0) { + return Promise.resolve([]); + } + return this.getNodes(ids, {}).then((elements: Array) => { + const children = elements + .filter((element: Element) => this.elements()[element.id]?.expanded) + .map((element: Element) => element.children) + .reduce((acc, val) => acc.concat(val), []); + return this.invalidate(children); + }); + } + updateElement(id: ElementID, data: Object) { this.props.setPersistedState({ [this.props.ax ? 'AXelements' : 'elements']: {