Skip to content

Commit

Permalink
Prevent empty data from rendering move page modal.
Browse files Browse the repository at this point in the history
There seems to be an issue where sometimes, possibly when a value is both simultaneously being mutated and queried from the cache, where a query component will return an empty data object, even though the query has finished loading and there are no errors.
This was causing our application to crash because the modal assumes that it is being passed a valid data object, based on assumptions being made in the PropTypes.

This change guards against this issue by not rendering the move page modal in this particular scenario. Other people have been reporting similar issues as recently as April 2019 which suggests that this could be an outstanding bug in our version of the react-apollo dependency. We can guard against it but there doesn't appear to be a well-understood fix at this time.
  • Loading branch information
samiwel committed Aug 1, 2019
1 parent 5bfc05c commit 4edaac3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions eq-author/src/App/page/Design/PageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import IconButtonDelete from "components/buttons/IconButtonDelete";
import DeleteConfirmDialog from "components/DeleteConfirmDialog";
import iconPage from "./icon-dialog-page.svg";
import { isFunction, flowRight } from "lodash";
import { isFunction, flowRight, isEmpty } from "lodash";
import PropTypes from "prop-types";
import { propType } from "graphql-anywhere";
import gql from "graphql-tag";
Expand Down Expand Up @@ -66,7 +66,7 @@ export class PageHeader extends React.Component {
renderMovePageModal = ({ loading, error, data }) => {
const { page } = this.props;

if (loading || error) {
if (loading || error || isEmpty(data)) {
return null;
}

Expand Down
9 changes: 9 additions & 0 deletions eq-author/src/App/page/Design/PageHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ describe("Question Page Editor", () => {

expect(moveWrapper.prop("isOpen")).toEqual(true);
});

it("should not render if no data", () => {
expect(
wrapper.find(MovePageQuery).prop("children")({
data: {},
})
).toBeNull();
});

it("should call handler when confirmed", () => {
const moveWrapper = shallow(
wrapper.find(MovePageQuery).prop("children")({
Expand Down

0 comments on commit 4edaac3

Please sign in to comment.