Skip to content

Commit f397f8a

Browse files
committed
Fix ExternalWrapper pattern matching ids.
1 parent 1cd9c05 commit f397f8a

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

dash/dash-renderer/src/actions/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {getAction} from './constants';
66
import cookie from 'cookie';
77
import {validateCallbacksToLayout} from './dependencies';
88
import {includeObservers, getLayoutCallbacks} from './dependencies_ts';
9-
import {getPath} from './paths';
9+
import {computePaths, getPath} from './paths';
1010

1111
export const onError = createAction(getAction('ON_ERROR'));
1212
export const setAppLifecycle = createAction(getAction('SET_APP_LIFECYCLE'));
@@ -21,6 +21,14 @@ export const updateProps = createAction(getAction('ON_PROP_CHANGE'));
2121
export const insertComponent = createAction(getAction('INSERT_COMPONENT'));
2222
export const removeComponent = createAction(getAction('REMOVE_COMPONENT'));
2323

24+
export const addComponentToLayout = payload => (dispatch, getState) => {
25+
const {paths} = getState();
26+
dispatch(insertComponent(payload));
27+
dispatch(
28+
setPaths(computePaths(payload.component, payload.componentPath, paths))
29+
);
30+
};
31+
2432
export const dispatchError = dispatch => (message, lines) =>
2533
dispatch(
2634
onError({

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import React, {useState, useEffect} from 'react';
2-
import {useDispatch} from 'react-redux';
2+
import {batch, useDispatch} from 'react-redux';
33

44
import {DashLayoutPath} from '../types/component';
55
import DashWrapper from './DashWrapper';
6-
import {insertComponent, removeComponent, updateProps} from '../actions';
6+
import {
7+
addComponentToLayout,
8+
notifyObservers,
9+
removeComponent,
10+
updateProps
11+
} from '../actions';
712

813
type Props = {
914
componentPath: DashLayoutPath;
@@ -21,14 +26,14 @@ function ExternalWrapper({
2126
componentPath,
2227
...props
2328
}: Props) {
24-
const dispatch = useDispatch();
29+
const dispatch: any = useDispatch();
2530
const [inserted, setInserted] = useState(false);
2631

2732
useEffect(() => {
2833
// Give empty props for the inserted components.
2934
// The props will come from the parent so they can be updated.
3035
dispatch(
31-
insertComponent({
36+
addComponentToLayout({
3237
component: {
3338
type: componentType,
3439
namespace: componentNamespace,
@@ -44,7 +49,10 @@ function ExternalWrapper({
4449
}, []);
4550

4651
useEffect(() => {
47-
dispatch(updateProps({itempath: componentPath, props}));
52+
batch(() => {
53+
dispatch(updateProps({itempath: componentPath, props}));
54+
dispatch(notifyObservers({id: props.id, props}));
55+
});
4856
}, [props]);
4957

5058
if (!inserted) {

tests/integration/renderer/test_external_component.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dash import Dash, html, dcc, html, Input, Output, State
1+
from dash import Dash, html, dcc, html, Input, Output, State, MATCH
22
from dash_test_components import ExternalComponent
33

44

@@ -17,10 +17,13 @@ def test_rext001_render_external_component(dash_duo):
1717
"namespace": "dash_html_components",
1818
"props": {
1919
"id": "extra",
20-
"children": [html.Div("extra children", id="extra-children")],
20+
"children": [
21+
html.Div("extra children", id={"type": "extra", "index": 1})
22+
],
2123
},
2224
},
2325
),
26+
html.Div(html.Div(id={"type": "output", "index": 1}), id="out"),
2427
]
2528
)
2629

@@ -33,9 +36,20 @@ def test_rext001_render_external_component(dash_duo):
3336
def on_sync(_, value):
3437
return value
3538

39+
@app.callback(
40+
Output({"type": "output", "index": MATCH}, "children"),
41+
Input({"type": "extra", "index": MATCH}, "n_clicks"),
42+
prevent_initial_call=True,
43+
)
44+
def click(*_):
45+
return "clicked"
46+
3647
dash_duo.start_server(app)
3748
dash_duo.wait_for_text_to_equal("#external", "external")
3849
dash_duo.find_element("#sync-btn").click()
3950
dash_duo.wait_for_text_to_equal("#external", "synced")
4051

4152
dash_duo.wait_for_text_to_equal("#extra", "extra children")
53+
54+
dash_duo.find_element("#extra > div").click()
55+
dash_duo.wait_for_text_to_equal("#out", "clicked")

0 commit comments

Comments
 (0)