diff --git a/frontend/src/components/core/Maybe/Maybe.test.tsx b/frontend/src/components/core/Maybe/Maybe.test.tsx index 66369504651e..948a362739f0 100644 --- a/frontend/src/components/core/Maybe/Maybe.test.tsx +++ b/frontend/src/components/core/Maybe/Maybe.test.tsx @@ -56,6 +56,17 @@ describe("The Maybe component", () => { expect(spyShouldComponentUpdate).toHaveBeenCalled() expect(spyRender).toHaveBeenCalled() }) + + it("should call render() when a Maybe is first disabled", () => { + const spyShouldComponentUpdate = jest.spyOn( + Maybe.prototype, + "shouldComponentUpdate" + ) + const spyRender = jest.spyOn(Maybe.prototype, "render") + component.setProps({ name: "new name", enable: false }) + expect(spyShouldComponentUpdate).toHaveBeenCalled() + expect(spyRender).toHaveBeenCalled() + }) }) describe("when enable is false", () => { diff --git a/frontend/src/components/core/Maybe/Maybe.tsx b/frontend/src/components/core/Maybe/Maybe.tsx index cefbedfab26f..d96b269104de 100644 --- a/frontend/src/components/core/Maybe/Maybe.tsx +++ b/frontend/src/components/core/Maybe/Maybe.tsx @@ -30,7 +30,10 @@ class Maybe extends React.Component { nextState: Readonly, nextContext: any ): boolean { - return nextProps.enable + // We have our component update if either props.enable or nextProps.enable + // is true to ensure that we rerender in the case that an Element is + // removed by replacing it with an empty one (so goes from enabled->disabled). + return this.props.enable || nextProps.enable } public render(): React.ReactNode {