Skip to content
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

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

Open
chgiesse opened this issue Feb 25, 2025 · 4 comments

Comments

@chgiesse
Copy link

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!

@T4rk1n
Copy link
Contributor

T4rk1n commented Feb 25, 2025

dash 3.0.0rc3, 3.0.0rc2, 3.0.0rc1, 2.8.12

I think I've seen this bug reported before, can you confirm the bug is present in dash 2.x?

@chgiesse
Copy link
Author

You are insane, thanks for this rapid response! Yes can confirm, at least for 2.18.2. If it helps, I can also check prev. versions! Best regards,
Christian

@T4rk1n
Copy link
Contributor

T4rk1n commented Feb 25, 2025

You are insane, thanks for this rapid response! Yes can confirm, at least for 2.18.2. If it helps, I can also check prev. versions! Best regards, Christian

Thanks, just wanted to confirm it is not a regression in 3.0.0 RC.

@chgiesse
Copy link
Author

Do you have an initial thought on why and where this behaviour appears? Would like to support here but I just started to go through the dash renderer since your big 3.0 changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants