Skip to content

Clean up react devtools warnings on our devtools #969

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

Merged
merged 2 commits into from
Oct 16, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Fixed
- [#969](https://github.com/plotly/dash/pull/969) Fix warnings emitted by react devtools coming from our own devtools components.

## [1.4.0] - 2019-10-08
### Added
- [#948](https://github.com/plotly/dash/pull/948) Support setting working directory for R apps run using the `dashr` fixture, primarily useful for tests with assets. `dashr.start_server` supports a `cwd` argument to set an explicit working directory, and has smarter defaults when it's omitted: if `app` is a path to an R script, uses the directory of that path; if `app` is a string, uses the directory the test file itself is in.
Expand Down
372 changes: 201 additions & 171 deletions dash-renderer/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"webpack-serve": "^3.1.1",
"whatwg-fetch": "^2.0.2"
}
}
}
1 change: 0 additions & 1 deletion dash-renderer/src/actions/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const actionList = {
SET_APP_LIFECYCLE: 'SET_APP_LIFECYCLE',
SET_CONFIG: 'SET_CONFIG',
ON_ERROR: 'ON_ERROR',
RESOLVE_ERROR: 'RESOLVE_ERROR',
SET_HOOKS: 'SET_HOOKS',
};

Expand Down
1 change: 0 additions & 1 deletion dash-renderer/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const setAppLifecycle = createAction(getAction('SET_APP_LIFECYCLE'));
export const setConfig = createAction(getAction('SET_CONFIG'));
export const setHooks = createAction(getAction('SET_HOOKS'));
export const onError = createAction(getAction('ON_ERROR'));
export const resolveError = createAction(getAction('RESOLVE_ERROR'));

export function hydrateInitialOutputs() {
return function(dispatch, getState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {connect} from 'react-redux';
import {Component} from 'react';
import PropTypes from 'prop-types';
import Radium from 'radium';
import {includes, pluck} from 'ramda';
import uniqid from 'uniqid';
import {onError, revert} from '../../actions';

Expand All @@ -13,9 +12,14 @@ class UnconnectedComponentErrorBoundary extends Component {
myID: props.componentId,
myUID: uniqid(),
oldChildren: null,
hasError: false,
};
}

static getDerivedStateFromError(_) {
return {hasError: true};
}
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet Oct 16, 2019

Choose a reason for hiding this comment

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

Not finding code calling this function. How is the state updated to have hasError=true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


componentDidCatch(error, info) {
const {dispatch} = this.props;
dispatch(
Expand All @@ -32,30 +36,22 @@ class UnconnectedComponentErrorBoundary extends Component {

/* eslint-disable react/no-did-update-set-state */
componentDidUpdate(prevProps, prevState) {
const {error} = this.props;
const {myUID} = this.state;
const hasError = includes(myUID, pluck('myUID')(error.frontEnd));
const prevChildren = prevProps.children;
if (
!hasError &&
prevState.oldChildren !== prevProps.children &&
prevProps.children !== this.props.children
!this.state.hasError &&
prevChildren !== prevState.oldChildren &&
prevChildren !== this.props.children
) {
this.setState({
oldChildren: prevProps.children,
oldChildren: prevChildren,
});
}
}
/* eslint-enable react/no-did-update-set-state */

render() {
const {error} = this.props;
const {myUID} = this.state;
const hasError = includes(myUID, pluck('myUID')(error.frontEnd));

if (hasError) {
return this.state.oldChildren;
}
return this.props.children;
const {hasError, oldChildren} = this.state;
return hasError ? oldChildren : this.props.children;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@ class FrontEndError extends Component {
}

render() {
const {e, resolve, inAlertsTray} = this.props;
const {e, inAlertsTray} = this.props;
const {collapsed} = this.state;

let cardClasses;
// if resolve is defined, the error should be a standalone card
if (resolve) {
cardClasses = 'dash-error-card';
} else {
cardClasses = 'dash-error-card__content';
}
if (inAlertsTray) {
cardClasses += ' dash-error-card--alerts-tray';
}
const cardClasses =
'dash-error-card__content' +
(inAlertsTray ? ' dash-error-card--alerts-tray' : '');

/* eslint-disable no-inline-comments */
const errorHeader = (
Expand Down Expand Up @@ -178,7 +171,6 @@ FrontEndError.propTypes = {
timestamp: PropTypes.object,
error: errorPropTypes,
}),
resolve: PropTypes.func,
inAlertsTray: PropTypes.bool,
isListItem: PropTypes.bool,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class FrontEndErrorContainer extends Component {
const inAlertsTray = this.props.inAlertsTray;
let cardClasses = 'dash-error-card dash-error-card--container';

const errorElements = this.props.errors.map(error => {
return <FrontEndError e={error} isListItem={true} />;
const errorElements = this.props.errors.map((error, i) => {
return <FrontEndError e={error} isListItem={true} key={i} />;
});
if (inAlertsTray) {
cardClasses += ' dash-error-card--alerts-tray';
Expand All @@ -42,7 +42,6 @@ class FrontEndErrorContainer extends Component {

FrontEndErrorContainer.propTypes = {
errors: PropTypes.array,
resolve: PropTypes.func,
inAlertsTray: PropTypes.any,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@ import {connect} from 'react-redux';
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Radium from 'radium';
import {resolveError} from '../../actions';
import {DebugMenu} from './menu/DebugMenu.react';

class UnconnectedGlobalErrorContainer extends Component {
constructor(props) {
super(props);
}

resolveError(dispatch, type, myId) {
if (type === 'backEnd') {
dispatch(resolveError({type}));
// dispatch(revert);
} else {
dispatch(resolveError({myId, type}));
}
}

render() {
const {error, dispatch, dependenciesRequest} = this.props;
const {error, dependenciesRequest} = this.props;
return (
<div id="_dash-global-error-container">
<DebugMenu
error={error}
dependenciesRequest={dependenciesRequest}
dispatch={dispatch}
resolveError={this.resolveError}
>
<div id="_dash-app-content">{this.props.children}</div>
</DebugMenu>
Expand All @@ -40,15 +28,11 @@ UnconnectedGlobalErrorContainer.propTypes = {
children: PropTypes.object,
error: PropTypes.object,
dependenciesRequest: PropTypes.object,
dispatch: PropTypes.func,
};

const GlobalErrorContainer = connect(
state => ({
error: state.error,
dependenciesRequest: state.dependenciesRequest,
}),
dispatch => ({dispatch})
)(Radium(UnconnectedGlobalErrorContainer));
const GlobalErrorContainer = connect(state => ({
error: state.error,
dependenciesRequest: state.dependenciesRequest,
}))(Radium(UnconnectedGlobalErrorContainer));

export default GlobalErrorContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ export default class GlobalErrorOverlay extends Component {
}

render() {
const {resolve, visible, error, toastsEnabled} = this.props;
const {visible, error, toastsEnabled} = this.props;

let frontEndErrors;
if (toastsEnabled) {
const errors = concat(error.frontEnd, error.backEnd);

frontEndErrors = (
<FrontEndErrorContainer errors={errors} resolve={resolve} />
);
frontEndErrors = <FrontEndErrorContainer errors={errors} />;
}
return (
<div>
Expand All @@ -36,7 +34,6 @@ export default class GlobalErrorOverlay extends Component {

GlobalErrorOverlay.propTypes = {
children: PropTypes.object,
resolve: PropTypes.func,
visible: PropTypes.bool,
error: PropTypes.object,
toastsEnabled: PropTypes.any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DebugMenu extends Component {
toastsEnabled,
callbackGraphOpened,
} = this.state;
const {error, resolveError, dispatch, dependenciesRequest} = this.props;
const {error, dependenciesRequest} = this.props;

const menuClasses = opened
? 'dash-debug-menu dash-debug-menu--opened'
Expand Down Expand Up @@ -136,7 +136,6 @@ class DebugMenu extends Component {
{menuContent}
</div>
<GlobalErrorOverlay
resolve={(type, myId) => resolveError(dispatch, type, myId)}
error={error}
visible={
!(isEmpty(error.backEnd) && isEmpty(error.frontEnd))
Expand All @@ -154,8 +153,6 @@ DebugMenu.propTypes = {
children: PropTypes.object,
error: PropTypes.object,
dependenciesRequest: PropTypes.object,
resolveError: PropTypes.func,
dispatch: PropTypes.func,
};

export {DebugMenu};
27 changes: 2 additions & 25 deletions dash-renderer/src/reducers/error.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {findIndex, mergeRight, propEq, remove} from 'ramda';
import {mergeRight} from 'ramda';

const initialError = {
frontEnd: [],
backEnd: [],
};

function error(state = initialError, action) {
export default function error(state = initialError, action) {
switch (action.type) {
case 'ON_ERROR': {
if (action.payload.type === 'frontEnd') {
Expand All @@ -28,31 +28,8 @@ function error(state = initialError, action) {
return state;
}

case 'RESOLVE_ERROR': {
if (action.payload.type === 'frontEnd') {
const removeIdx = findIndex(
propEq('myUID', action.payload.myUID)
)(state.frontEnd);
return {
frontEnd: remove(removeIdx, 1, state.frontEnd),
backEnd: state.backEnd,
};
} else if (action.payload.type === 'backEnd') {
const removeIdx = findIndex(
propEq('myUID', action.payload.myUID)
)(state.backEnd);
return {
frontEnd: state.frontEnd,
backEnd: remove(removeIdx, 1, state.backEnd),
};
}
return state;
}

default: {
return state;
}
}
}

export default error;