Skip to content

Commit a9a5df5

Browse files
authored
Merge pull request #3183 from plotly/fix-external-wrapper-id
Fix external wrapper requiring id.
2 parents 43af268 + 6cf16b5 commit a9a5df5

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

@plotly/dash-test-components/src/components/ExternalComponent.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ const ExternalComponent = ({ id, text, input_id, extra_component }) => {
88

99
return (
1010
<div id={id}>
11-
<ExternalWrapper
12-
id={input_id}
13-
componentType="Input"
14-
componentNamespace="dash_core_components"
15-
value={text}
11+
{text && <ExternalWrapper
12+
13+
component={{
14+
type: "Input",
15+
namespace: "dash_core_components",
16+
props: {
17+
value: text,
18+
id: input_id
19+
}
20+
}}
1621
componentPath={[...ctx.componentPath, 'external']}
17-
/>
22+
/>}
1823
{
1924
extra_component &&
2025
<ExternalWrapper
21-
componentType={extra_component.type}
22-
componentNamespace={extra_component.namespace}
26+
component={extra_component}
2327
componentPath={[...ctx.componentPath, 'extra']}
24-
{...extra_component.props}
2528
/>}
2629
</div>
2730
)

dash/dash-renderer/src/wrapper/ExternalWrapper.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useState, useEffect} from 'react';
22
import {batch, useDispatch} from 'react-redux';
33

4-
import {DashLayoutPath} from '../types/component';
4+
import {DashComponent, DashLayoutPath} from '../types/component';
55
import DashWrapper from './DashWrapper';
66
import {
77
addComponentToLayout,
@@ -11,21 +11,14 @@ import {
1111
} from '../actions';
1212

1313
type Props = {
14+
component: DashComponent;
1415
componentPath: DashLayoutPath;
15-
componentType: string;
16-
componentNamespace: string;
17-
[k: string]: any;
1816
};
1917

2018
/**
2119
* For rendering components that are out of the regular layout tree.
2220
*/
23-
function ExternalWrapper({
24-
componentType,
25-
componentNamespace,
26-
componentPath,
27-
...props
28-
}: Props) {
21+
function ExternalWrapper({component, componentPath}: Props) {
2922
const dispatch: any = useDispatch();
3023
const [inserted, setInserted] = useState(false);
3124

@@ -34,11 +27,7 @@ function ExternalWrapper({
3427
// The props will come from the parent so they can be updated.
3528
dispatch(
3629
addComponentToLayout({
37-
component: {
38-
type: componentType,
39-
namespace: componentNamespace,
40-
props: props
41-
},
30+
component,
4231
componentPath
4332
})
4433
);
@@ -50,10 +39,19 @@ function ExternalWrapper({
5039

5140
useEffect(() => {
5241
batch(() => {
53-
dispatch(updateProps({itempath: componentPath, props}));
54-
dispatch(notifyObservers({id: props.id, props}));
42+
dispatch(
43+
updateProps({itempath: componentPath, props: component.props})
44+
);
45+
if (component.props.id) {
46+
dispatch(
47+
notifyObservers({
48+
id: component.props.id,
49+
props: component.props
50+
})
51+
);
52+
}
5553
});
56-
}, [props]);
54+
}, [component.props]);
5755

5856
if (!inserted) {
5957
return null;

tests/integration/renderer/test_external_component.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def test_rext001_render_external_component(dash_duo):
2323
},
2424
},
2525
),
26+
ExternalComponent(
27+
id="without-id",
28+
text="without-id",
29+
),
2630
html.Div(html.Div(id={"type": "output", "index": 1}), id="out"),
2731
]
2832
)
@@ -53,3 +57,5 @@ def click(*_):
5357

5458
dash_duo.find_element("#extra > div").click()
5559
dash_duo.wait_for_text_to_equal("#out", "clicked")
60+
61+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)