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

add generic error boundary, apply to preview iframe #779

Merged
merged 1 commit into from
Nov 11, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/components/PreviewPane/PreviewPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { List, Map } from 'immutable';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Frame from 'react-frame-component';
import registry from '../../lib/registry';
import ErrorBoundary from '../UI/ErrorBoundary/ErrorBoundary';
import { resolveWidget } from '../Widgets';
import { selectTemplateName, selectInferedField } from '../../reducers/collections';
import { INFERABLE_FIELDS } from '../../constants/fieldInference';
Expand Down Expand Up @@ -144,16 +145,20 @@ export default class PreviewPane extends React.Component {
return <Frame className="nc-previewPane-frame" head={styleEls} />;
}

return (<Frame
className="nc-previewPane-frame"
head={styleEls}
initialContent={`
const initialContent = `
<!DOCTYPE html>
<html>
<head><base target="_blank"/></head>
<body><div></div></body>
</html>`}
><PreviewContent {...{ previewComponent, previewProps }}/></Frame>);
</html>
`;
return (
<ErrorBoundary>
<Frame className="nc-previewPane-frame" head={styleEls} initialContent={initialContent}>
<PreviewContent {...{ previewComponent, previewProps }}/>
</Frame>
</ErrorBoundary>
);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/components/UI/ErrorBoundary/ErrorBoundary.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.nc-errorBoundary {
padding: 0 20px;
}

.nc-errorBoundary-heading,
.nc-errorBoundary-link {
color: var(--errorColor);
}
35 changes: 35 additions & 0 deletions src/components/UI/ErrorBoundary/ErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import PropTypes from 'prop-types';
import React from 'react';

const ErrorComponent = () => {
const issueUrl = "https://github.com/netlify/netlify-cms/issues/new";
return (
<div className="nc-errorBoundary">
<h1 className="nc-errorBoundary-heading">Sorry!</h1>
<p>
<span>There's been an error - please </span>
<a href={issueUrl} target="_blank" className="nc-errorBoundary-link">report it</a>!
</p>
</div>
);
};

export default class ErrorBoundary extends React.Component {
static propTypes = {
render: PropTypes.element,
};

state = {
hasError: false,
};

componentDidCatch(error) {
console.error(error);
this.setState({ hasError: true });
}

render() {
const errorComponent = this.props.errorComponent || <ErrorComponent/>;
return this.state.hasError ? errorComponent : this.props.children;
}
}
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import "./components/UI/loader/Loader.css";
@import "./components/UI/toast/Toast.css";
@import "./components/UI/Dialog/Dialog.css";
@import "./components/UI/ErrorBoundary/ErrorBoundary.css";
@import "./components/UnpublishedListing/UnpublishedListing.css";
@import "./components/UnpublishedListing/UnpublishedListingCardMeta.css";
@import "./components/Widgets/BooleanControl.css";
Expand Down