Skip to content

Commit cea5aba

Browse files
setProps and rendered event ordering causing unsent callbacks (#1415)
1 parent 98e81fc commit cea5aba

File tree

14 files changed

+200
-12
lines changed

14 files changed

+200
-12
lines changed

@plotly/dash-test-components/babel.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ const presets = [
33
'@babel/preset-react'
44
];
55

6-
module.exports = { presets };
6+
const plugins = [
7+
'@babel/plugin-syntax-dynamic-import'
8+
];
9+
10+
module.exports = { presets, plugins };

@plotly/dash-test-components/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@plotly/dash-test-components/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
"devDependencies": {
2323
"@babel/cli": "^7.4.0",
2424
"@babel/core": "^7.4.0",
25+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
2526
"@babel/preset-env": "^7.4.1",
2627
"@babel/preset-react": "^7.0.0",
28+
"@plotly/dash-component-plugins": "^1.2.0",
29+
"@plotly/webpack-dash-dynamic-import": "^1.1.5",
2730
"babel-loader": "^8.0.5",
2831
"npm-run-all": "^4.1.5",
2932
"react": "16.13.0",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import PropTypes from 'prop-types';
2+
import React, { Suspense } from 'react';
3+
import { asyncDecorator } from '@plotly/dash-component-plugins';
4+
import asyncComponentLoader from './../fragments/AsyncComponentLoader';
5+
6+
const AsyncComponent = props => (<Suspense fallback={null}>
7+
<RealAsyncComponent {...props} />
8+
</Suspense>);
9+
10+
const RealAsyncComponent = asyncDecorator(AsyncComponent, asyncComponentLoader);
11+
12+
AsyncComponent.propTypes = {
13+
id: PropTypes.string,
14+
value: PropTypes.string
15+
};
16+
17+
AsyncComponent.defaultProps = {};
18+
19+
export default AsyncComponent;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import PropTypes from 'prop-types';
2+
import React, { Fragment } from 'react';
3+
4+
const CollapseComponent = props => (<Fragment>
5+
{display ? props.children : null}
6+
</Fragment>);
7+
8+
CollapseComponent.propTypes = {
9+
children: PropTypes.node,
10+
display: PropTypes.bool,
11+
id: PropTypes.string
12+
};
13+
14+
CollapseComponent.defaultProps = {
15+
display: false
16+
};
17+
18+
export default CollapseComponent;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import PropTypes from 'prop-types';
2+
import React from 'react';
3+
4+
const DelayedEventComponent = ({ id, n_clicks, setProps }) => (<button
5+
id={id}
6+
onClick={() => setTimeout(() => setProps({ n_clicks: n_clicks + 1 }), 20)}
7+
/>);
8+
9+
DelayedEventComponent.propTypes = {
10+
id: PropTypes.string,
11+
n_clicks: PropTypes.number
12+
};
13+
14+
DelayedEventComponent.defaultProps = {
15+
n_clicks: 0
16+
};
17+
18+
export default DelayedEventComponent;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import PropTypes from 'prop-types';
2+
import React, { Fragment } from 'react';
3+
4+
const FragmentComponent = props => (<Fragment>
5+
{props.children}
6+
</Fragment>);
7+
8+
FragmentComponent.propTypes = {
9+
children: PropTypes.node,
10+
id: PropTypes.string
11+
};
12+
13+
FragmentComponent.defaultProps = {};
14+
15+
export default FragmentComponent;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import PropTypes from 'prop-types';
2+
import React, { Fragment } from 'react';
3+
import { asyncDecorator } from '@plotly/dash-component-plugins';
4+
5+
/**
6+
* MyComponent description
7+
*/
8+
const AsyncComponent = ({ value }) => (<Fragment>
9+
{value}
10+
</Fragment>);
11+
12+
AsyncComponent.propTypes = {
13+
id: PropTypes.string,
14+
value: PropTypes.string
15+
};
16+
17+
AsyncComponent.defaultProps = {};
18+
19+
export default AsyncComponent;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => import('./AsyncComponent');
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
import AsyncComponent from './components/AsyncComponent';
2+
import CollapseComponent from './components/CollapseComponent';
3+
import DelayedEventComponent from './components/DelayedEventComponent';
4+
import FragmentComponent from './components/FragmentComponent';
15
import StyledComponent from './components/StyledComponent';
26
import MyPersistedComponent from './components/MyPersistedComponent';
37
import MyPersistedComponentNested from './components/MyPersistedComponentNested';
48

59

610
export {
7-
StyledComponent, MyPersistedComponent, MyPersistedComponentNested
11+
AsyncComponent,
12+
CollapseComponent,
13+
DelayedEventComponent,
14+
FragmentComponent,
15+
MyPersistedComponent,
16+
MyPersistedComponentNested,
17+
StyledComponent
818
};

0 commit comments

Comments
 (0)