Skip to content

Fix external wrapper requiring id. #3183

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

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 12 additions & 9 deletions @plotly/dash-test-components/src/components/ExternalComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ const ExternalComponent = ({ id, text, input_id, extra_component }) => {

return (
<div id={id}>
<ExternalWrapper
id={input_id}
componentType="Input"
componentNamespace="dash_core_components"
value={text}
{text && <ExternalWrapper

component={{
type: "Input",
namespace: "dash_core_components",
props: {
value: text,
id: input_id
}
}}
componentPath={[...ctx.componentPath, 'external']}
/>
/>}
{
extra_component &&
<ExternalWrapper
componentType={extra_component.type}
componentNamespace={extra_component.namespace}
component={extra_component}
componentPath={[...ctx.componentPath, 'extra']}
{...extra_component.props}
/>}
</div>
)
Expand Down
34 changes: 16 additions & 18 deletions dash/dash-renderer/src/wrapper/ExternalWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState, useEffect} from 'react';
import {batch, useDispatch} from 'react-redux';

import {DashLayoutPath} from '../types/component';
import {DashComponent, DashLayoutPath} from '../types/component';
import DashWrapper from './DashWrapper';
import {
addComponentToLayout,
Expand All @@ -11,21 +11,14 @@ import {
} from '../actions';

type Props = {
component: DashComponent;
componentPath: DashLayoutPath;
componentType: string;
componentNamespace: string;
[k: string]: any;
};

/**
* For rendering components that are out of the regular layout tree.
*/
function ExternalWrapper({
componentType,
componentNamespace,
componentPath,
...props
}: Props) {
function ExternalWrapper({component, componentPath}: Props) {
const dispatch: any = useDispatch();
const [inserted, setInserted] = useState(false);

Expand All @@ -34,11 +27,7 @@ function ExternalWrapper({
// The props will come from the parent so they can be updated.
dispatch(
addComponentToLayout({
component: {
type: componentType,
namespace: componentNamespace,
props: props
},
component,
componentPath
})
);
Expand All @@ -50,10 +39,19 @@ function ExternalWrapper({

useEffect(() => {
batch(() => {
dispatch(updateProps({itempath: componentPath, props}));
dispatch(notifyObservers({id: props.id, props}));
dispatch(
updateProps({itempath: componentPath, props: component.props})
);
if (component.props.id) {
dispatch(
notifyObservers({
id: component.props.id,
props: component.props
})
);
}
});
}, [props]);
}, [component.props]);

if (!inserted) {
return null;
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/renderer/test_external_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def test_rext001_render_external_component(dash_duo):
},
},
),
ExternalComponent(
id="without-id",
text="without-id",
),
html.Div(html.Div(id={"type": "output", "index": 1}), id="out"),
]
)
Expand Down Expand Up @@ -53,3 +57,5 @@ def click(*_):

dash_duo.find_element("#extra > div").click()
dash_duo.wait_for_text_to_equal("#out", "clicked")

assert dash_duo.get_logs() == []