Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerender Maybe components when they're first disabled #2617

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/src/components/core/Maybe/Maybe.test.tsx
Expand Up @@ -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", () => {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/core/Maybe/Maybe.tsx
Expand Up @@ -30,7 +30,10 @@ class Maybe extends React.Component<Props, State> {
nextState: Readonly<State>,
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 {
Expand Down