Skip to content

Commit bc0735c

Browse files
committed
Remove dynamic loading.
1 parent 75e70c6 commit bc0735c

19 files changed

+90
-605
lines changed

dash/_validate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from collections.abc import MutableSequence
23
import re
34
from textwrap import dedent
@@ -356,6 +357,13 @@ def check_obsolete(kwargs):
356357
See https://dash.plotly.com for details.
357358
"""
358359
)
360+
if key in ["dynamic_loading", "preloaded_libraries"]:
361+
# Only warns as this was only available for a short time.
362+
print(
363+
f"{key} has been removed and no longer a valid keyword argument in Dash.",
364+
file=sys.stderr,
365+
)
366+
continue
359367
# any other kwarg mimic the built-in exception
360368
raise TypeError(f"Dash() got an unexpected keyword argument '{key}'")
361369

dash/dash-renderer/src/APIController.react.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import {batch, connect} from 'react-redux';
22
import {includes, isEmpty} from 'ramda';
3-
import React, {
4-
useEffect,
5-
useRef,
6-
useState,
7-
createContext,
8-
useCallback
9-
} from 'react';
3+
import React, {useEffect, useRef, useState, createContext} from 'react';
104
import PropTypes from 'prop-types';
115
import TreeContainer from './TreeContainer';
126
import GlobalErrorContainer from './components/error/GlobalErrorContainer.react';
@@ -27,7 +21,6 @@ import {getAppState} from './reducers/constants';
2721
import {STATUS} from './constants/constants';
2822
import {getLoadingState, getLoadingHash} from './utils/TreeContainer';
2923
import wait from './utils/wait';
30-
import LibraryManager from './libraries/LibraryManager';
3124

3225
export const DashContext = createContext({});
3326

@@ -53,10 +46,6 @@ const UnconnectedContainer = props => {
5346
if (!events.current) {
5447
events.current = new EventEmitter();
5548
}
56-
57-
const [libraryReady, setLibraryReady] = useState(false);
58-
const onLibraryReady = useCallback(() => setLibraryReady(true), []);
59-
6049
const renderedTree = useRef(false);
6150

6251
const propsRef = useRef({});
@@ -71,9 +60,7 @@ const UnconnectedContainer = props => {
7160
})
7261
});
7362

74-
useEffect(
75-
storeEffect.bind(null, props, events, setErrorLoading, libraryReady)
76-
);
63+
useEffect(storeEffect.bind(null, props, events, setErrorLoading));
7764

7865
useEffect(() => {
7966
if (renderedTree.current) {
@@ -130,23 +117,14 @@ const UnconnectedContainer = props => {
130117
content = <div className='_dash-loading'>Loading...</div>;
131118
}
132119

133-
return (
134-
<LibraryManager
135-
requests_pathname_prefix={config.requests_pathname_prefix}
136-
onReady={onLibraryReady}
137-
ready={libraryReady}
138-
layout={layoutRequest && layoutRequest.content}
139-
>
140-
{config && config.ui === true ? (
141-
<GlobalErrorContainer>{content}</GlobalErrorContainer>
142-
) : (
143-
content
144-
)}
145-
</LibraryManager>
120+
return config && config.ui === true ? (
121+
<GlobalErrorContainer>{content}</GlobalErrorContainer>
122+
) : (
123+
content
146124
);
147125
};
148126

149-
function storeEffect(props, events, setErrorLoading, libraryReady) {
127+
function storeEffect(props, events, setErrorLoading) {
150128
const {
151129
appLifecycle,
152130
dependenciesRequest,
@@ -165,7 +143,7 @@ function storeEffect(props, events, setErrorLoading, libraryReady) {
165143
}
166144
dispatch(apiThunk('_dash-layout', 'GET', 'layoutRequest'));
167145
} else if (layoutRequest.status === STATUS.OK) {
168-
if (isEmpty(layout) && libraryReady) {
146+
if (isEmpty(layout)) {
169147
if (typeof hooks.layout_post === 'function') {
170148
hooks.layout_post(layoutRequest.content);
171149
}
@@ -208,8 +186,7 @@ function storeEffect(props, events, setErrorLoading, libraryReady) {
208186
layoutRequest.status === STATUS.OK &&
209187
!isEmpty(layout) &&
210188
// Hasn't already hydrated
211-
appLifecycle === getAppState('STARTED') &&
212-
libraryReady
189+
appLifecycle === getAppState('STARTED')
213190
) {
214191
let hasError = false;
215192
try {
@@ -258,8 +235,7 @@ const Container = connect(
258235
graphs: state.graphs,
259236
history: state.history,
260237
error: state.error,
261-
config: state.config,
262-
paths: state.paths
238+
config: state.config
263239
}),
264240
dispatch => ({dispatch})
265241
)(UnconnectedContainer);

dash/dash-renderer/src/CheckedComponent.react.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

dash/dash-renderer/src/TreeContainer.js

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,79 @@
11
import React, {Component, memo, useContext} from 'react';
22
import PropTypes from 'prop-types';
3+
import Registry from './registry';
4+
import {propTypeErrorHandler} from './exceptions';
35
import {
46
addIndex,
57
assoc,
68
assocPath,
79
concat,
810
dissoc,
911
equals,
10-
has,
1112
isEmpty,
1213
isNil,
14+
has,
1315
keys,
1416
map,
1517
mapObjIndexed,
16-
path as rpath,
17-
pathOr,
18+
mergeRight,
1819
pick,
1920
pickBy,
2021
propOr,
22+
path as rpath,
23+
pathOr,
2124
type
2225
} from 'ramda';
23-
import {batch} from 'react-redux';
24-
2526
import {notifyObservers, updateProps, onError} from './actions';
2627
import isSimpleComponent from './isSimpleComponent';
2728
import {recordUiEdit} from './persistence';
2829
import ComponentErrorBoundary from './components/error/ComponentErrorBoundary.react';
30+
import checkPropTypes from './checkPropTypes';
2931
import {getWatchedKeys, stringifyId} from './actions/dependencies';
3032
import {
3133
getLoadingHash,
3234
getLoadingState,
3335
validateComponent
3436
} from './utils/TreeContainer';
3537
import {DashContext} from './APIController.react';
36-
import LibraryComponent from './libraries/LibraryComponent';
38+
import {batch} from 'react-redux';
3739

3840
const NOT_LOADING = {
3941
is_loading: false
4042
};
4143

44+
function CheckedComponent(p) {
45+
const {element, extraProps, props, children, type} = p;
46+
47+
const errorMessage = checkPropTypes(
48+
element.propTypes,
49+
props,
50+
'component prop',
51+
element
52+
);
53+
if (errorMessage) {
54+
propTypeErrorHandler(errorMessage, props, type);
55+
}
56+
57+
return createElement(element, props, extraProps, children);
58+
}
59+
60+
CheckedComponent.propTypes = {
61+
children: PropTypes.any,
62+
element: PropTypes.any,
63+
layout: PropTypes.any,
64+
props: PropTypes.any,
65+
extraProps: PropTypes.any,
66+
id: PropTypes.string
67+
};
68+
69+
function createElement(element, props, extraProps, children) {
70+
const allProps = mergeRight(props, extraProps);
71+
if (Array.isArray(children)) {
72+
return React.createElement(element, allProps, ...children);
73+
}
74+
return React.createElement(element, allProps, children);
75+
}
76+
4277
function isDryComponent(obj) {
4378
return (
4479
type(obj) === 'Object' &&
@@ -215,6 +250,8 @@ class BaseTreeContainer extends Component {
215250
}
216251
validateComponent(_dashprivate_layout);
217252

253+
const element = Registry.resolve(_dashprivate_layout);
254+
218255
// Hydrate components props
219256
const childrenProps = pathOr(
220257
[],
@@ -418,14 +455,17 @@ class BaseTreeContainer extends Component {
418455
dispatch={_dashprivate_dispatch}
419456
error={_dashprivate_error}
420457
>
421-
<LibraryComponent
422-
children={children}
423-
type={_dashprivate_layout.type}
424-
namespace={_dashprivate_layout.namespace}
425-
props={props}
426-
extraProps={extraProps}
427-
props_check={_dashprivate_config.props_check}
428-
/>
458+
{_dashprivate_config.props_check ? (
459+
<CheckedComponent
460+
children={children}
461+
element={element}
462+
props={props}
463+
extraProps={extraProps}
464+
type={_dashprivate_layout.type}
465+
/>
466+
) : (
467+
createElement(element, props, extraProps, children)
468+
)}
429469
</ComponentErrorBoundary>
430470
);
431471
}

dash/dash-renderer/src/actions/callbacks.ts

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
CallbackResponseData
3535
} from '../types/callbacks';
3636
import {isMultiValued, stringifyId, isMultiOutputProp} from './dependencies';
37-
import {crawlLayout, urlBase} from './utils';
37+
import {urlBase} from './utils';
3838
import {getCSRFHeader} from '.';
3939
import {createAction, Action} from 'redux-actions';
4040
import {addHttpHeaders} from '../actions';
@@ -44,9 +44,6 @@ import {handlePatch, isPatch} from './patch';
4444
import {getPath} from './paths';
4545

4646
import {requestDependencies} from './requestDependencies';
47-
import loadLibrary from '../libraries/loadLibrary';
48-
import fetchDist from '../libraries/fetchDist';
49-
import {setLibraryLoaded} from './libraries';
5047

5148
export const addBlockedCallbacks = createAction<IBlockedCallback[]>(
5249
CallbackActionType.AddBlocked
@@ -366,7 +363,6 @@ function handleServerside(
366363
let runningOff: any;
367364
let progressDefault: any;
368365
let moreArgs = additionalArgs;
369-
const libraries = Object.keys(getState().libraries);
370366

371367
if (running) {
372368
sideUpdate(running.running, dispatch, paths);
@@ -512,41 +508,8 @@ function handleServerside(
512508
}
513509

514510
if (!long || data.response !== undefined) {
515-
const newLibs: string[] = [];
516-
Object.values(data.response as any).forEach(
517-
(newData: any) => {
518-
Object.values(newData).forEach(newProp => {
519-
crawlLayout(newProp, (c: any) => {
520-
if (
521-
c.namespace &&
522-
!libraries.includes(c.namespace) &&
523-
!newLibs.includes(c.namespace)
524-
) {
525-
newLibs.push(c.namespace);
526-
}
527-
});
528-
});
529-
}
530-
);
531-
if (newLibs.length) {
532-
fetchDist(
533-
getState().config.requests_pathname_prefix,
534-
newLibs
535-
)
536-
.then(data => {
537-
return Promise.all(data.map(loadLibrary));
538-
})
539-
.then(() => {
540-
completeJob();
541-
finishLine(data);
542-
dispatch(
543-
setLibraryLoaded({libraries: newLibs})
544-
);
545-
});
546-
} else {
547-
completeJob();
548-
finishLine(data);
549-
}
511+
completeJob();
512+
finishLine(data);
550513
} else {
551514
// Poll chain.
552515
setTimeout(

dash/dash-renderer/src/actions/libraries.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)