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

Improve performance of context components re-rendering #3066

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
57 changes: 10 additions & 47 deletions dash/dash-renderer/src/APIController.react.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {batch, connect} from 'react-redux';
import {includes, isEmpty} from 'ramda';
import React, {useEffect, useRef, useState, createContext} from 'react';
import React, {useEffect, useRef, useState} from 'react';

import PropTypes from 'prop-types';
import TreeContainer from './TreeContainer';
import GlobalErrorContainer from './components/error/GlobalErrorContainer.react';
import {
dispatchError,
Expand All @@ -19,11 +19,9 @@ import {EventEmitter} from './actions/utils';
import {applyPersistence} from './persistence';
import {getAppState} from './reducers/constants';
import {STATUS} from './constants/constants';
import {getLoadingState, getLoadingHash} from './utils/TreeContainer';
import wait from './utils/wait';
import isSimpleComponent from './isSimpleComponent';

export const DashContext = createContext({});
import DashWrapper from './wrapper/DashWrapper';

/**
* Fire off API calls for initialization
Expand All @@ -37,8 +35,7 @@ const UnconnectedContainer = props => {
dependenciesRequest,
error,
layoutRequest,
layout,
loadingMap
layout
} = props;

const [errorLoading, setErrorLoading] = useState(false);
Expand All @@ -49,18 +46,6 @@ const UnconnectedContainer = props => {
}
const renderedTree = useRef(false);

const propsRef = useRef({});
propsRef.current = props;

const provider = useRef({
fn: () => ({
_dashprivate_config: propsRef.current.config,
_dashprivate_dispatch: propsRef.current.dispatch,
_dashprivate_graphs: propsRef.current.graphs,
_dashprivate_loadingMap: propsRef.current.loadingMap
})
});

useEffect(storeEffect.bind(null, props, events, setErrorLoading));

useEffect(() => {
Expand Down Expand Up @@ -97,46 +82,26 @@ const UnconnectedContainer = props => {
renderedTree.current = true;

content = (
<DashContext.Provider value={provider.current}>
<>
{Array.isArray(layout) ? (
layout.map((c, i) =>
isSimpleComponent(c) ? (
c
) : (
<TreeContainer
<DashWrapper
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, new component - is this going to break any legacy code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it shouldn't as this is an internal component.

_dashprivate_error={error}
_dashprivate_layout={c}
_dashprivate_loadingState={getLoadingState(
c,
[i],
loadingMap
)}
_dashprivate_loadingStateHash={getLoadingHash(
[i],
loadingMap
)}
_dashprivate_path={`[${i}]`}
_dashprivate_path={[i]}
key={i}
/>
)
)
) : (
<TreeContainer
<DashWrapper
_dashprivate_error={error}
_dashprivate_layout={layout}
_dashprivate_loadingState={getLoadingState(
layout,
[],
loadingMap
)}
_dashprivate_loadingStateHash={getLoadingHash(
[],
loadingMap
)}
_dashprivate_path={'[]'}
_dashprivate_path={[]}
/>
)}
</DashContext.Provider>
</>
);
} else {
content = <div className='_dash-loading'>Loading...</div>;
Expand Down Expand Up @@ -242,7 +207,6 @@ UnconnectedContainer.propTypes = {
hooks: PropTypes.object,
layoutRequest: PropTypes.object,
layout: PropTypes.any,
loadingMap: PropTypes.any,
history: PropTypes.any,
error: PropTypes.object,
config: PropTypes.object
Expand All @@ -256,7 +220,6 @@ const Container = connect(
hooks: state.hooks,
layoutRequest: state.layoutRequest,
layout: state.layout,
loadingMap: state.loadingMap,
graphs: state.graphs,
history: state.history,
error: state.error,
Expand Down
Loading