Skip to content

Adding new Pattern Matching components don't trigger their related callback #3191

Open
@chgiesse

Description

@chgiesse

Describe your context

dash                 3.0.0rc3, 3.0.0rc2, 3.0.0rc1, 2.8.12
  • not front end related

Describe the bug
Pattern matching callback that should be triggered as soon as a related component is present in the layout just fire the first time the page is loaded. New components that get add by the callback itself should trigger the callback again but those trigger don't happen.

MRE

# app.py
from dash import Dash, html, page_container, dcc, callback, MATCH, Input, Output
from pages.components import LacyContainer
import time

app = Dash(__name__, use_pages=True)

col_style = {
    "display": "flex",
    "flexDirection": "column",
    "gap": "2rem",
}

row_style = {
    "display": "flex", 
    "flexDirection": "row", 
    "gap": "4rem", 
    "margin": "2rem"
}

app.layout = html.Div(
    style=row_style,
    children=[
        html.Div(
            style=col_style,
            children=[
                dcc.Link("Page - 1", href="/page-1"),
                dcc.Link("Page - 2", href="/page-2"),
            ]
        ),
        html.Div(page_container),
    ],
)

@callback(
    Output(LacyContainer.ids.container(MATCH), "children"),
    Input(LacyContainer.ids.container(MATCH), "id")
)

def load_lacy(lacy_id):
    time.sleep(1.3)
    lacy_index = lacy_id.get('index')
    children = (
        html.Div(
            children=[
                html.Div(lacy_index),
                LacyContainer(dcc.Loading(display="show"), index=3),     
            ],
            style=col_style
        )
        if lacy_index < 4 else
        html.Div(
            lacy_index
        )
    )

    return children

if __name__ == "__main__":
    app.run(debug=True, port=3000)
# pages/page1.py
from dash import dcc, register_page
from .components import LacyContainer

register_page(__name__, path="/page-1")


def layout(**kwargs):
    return LacyContainer(dcc.Loading(display="show"), index=1)
# pages/page2.py
from dash import dcc, register_page
from .components import LacyContainer

register_page(__name__, path="/page-2")


def layout(**kwargs):
    return LacyContainer(dcc.Loading(display="show"), index=2)
# components.py
from dash import html


class LacyContainer(html.Div):
    class ids:
        container = lambda idx: {"index": idx, "type": "lacy-container"}

    def __init__(self, children, index, **kwargs):
        super().__init__(children, id=self.ids.container(index), **kwargs)

Expected behavior
The expected behaviour would be:

  1. Page is loaded and contains multiple "lacy components" with a dict ID
  2. lacy component trigger the callback
  3. callback itself returns new "lacy components" which trigger the callback again up to the point, no more lacy component is present in the layout

Screenshots

The dots underitems should trigger the callback and should be replaced, but this never happens.

Thanks in advance and many thanks for your great work!

Metadata

Metadata

Assignees

Labels

P2considered for next cyclebugsomething brokendash-3.0Going in dash-3.0 release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions