Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/components/CodeEditor/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Remarkable from 'remarkable';
import {LiveProvider, LiveEditor} from '@gaearon/react-live';
import {colors, media} from 'theme';
import MetaTitle from 'templates/components/MetaTitle';
import ErrorBoundary from '../ErrorBoundary';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

import ErrorBoundary from 'components/ErrorBoundary';


const compile = code =>
Babel.transform(code, {presets: ['es2015', 'react']}).code; // eslint-disable-line no-undef
Expand Down Expand Up @@ -285,4 +286,4 @@ class CodeEditor extends Component {
};
}

export default CodeEditor;
export default ErrorBoundary(CodeEditor);
39 changes: 39 additions & 0 deletions src/components/ErrorBoundary/ErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/

'use strict';

import React, {Component} from 'react';

function ErrorBoundary(WrappedComponent) {
return class extends Component{
constructor(props, context) {
super(props, context);

this.state = {
error: null,
};
}

componentDidCatch(error) {
this.setState({ error });
}

render() {
console.log(this.state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this^ 😄

if (this.state.error) {
alert('Error, try to whitelist the site in AdBlocker/Cookie Whitelist');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right way to warn people about this. I think a console.error log would be reasonable though. Maybe something like:

If you're using an ad-blocker or have disabled cookies,
Consider adding this website to the whitelist.

We should also keep in mind that not all errors are caused by this so our wording shouldn't be overly assertive that this is definitely the cause/fix. Users might see an error even if they aren't using adblockers and haven't disabled cookies, and that would be confusing.

return;
}
return <WrappedComponent {...this.props} />;
}
}
}

export default ErrorBoundary;
14 changes: 14 additions & 0 deletions src/components/ErrorBoundary/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/

'use strict';

import ErrorBoundary from './ErrorBoundary';

export default ErrorBoundary;
3 changes: 2 additions & 1 deletion src/layouts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import '../prism-styles';
import 'glamor/reset';
import 'css/reset.css';
import 'css/algolia.css';
import ErrorBoundary from '../components/ErrorBoundary';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

import ErrorBoundary from 'components/ErrorBoundary';


class Template extends Component {
componentDidMount() {
Expand Down Expand Up @@ -82,4 +83,4 @@ class Template extends Component {
}
}

export default Template;
export default ErrorBoundary(Template);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors in the template will actually result in a totally empty/white page. This is probably not great. We should show something as a fallback in the browser (in addition to logging error info to the console).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest as the fallback?
Maybe we can use a modal (using react-modal) here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to show a basic error page. It doesn't have to look super pretty. @joecritch or I can pretty it up.