Callbacks triggered unnecessarily with MATCH - (Bug + Workaround)

Hey All, I have stumbled upon an interesting issue that relates closely to what I have been working on. When adding a component that is subject to a MATCH callback, say index=2, instead of triggering the callback for the added item, all indices less than that index are triggered (index = 0, 1, 2) with the following callback context for each:

ctx.triggered=[{'prop_id': '.', 'value': None}]
ctx.triggered_id=None
ctx.triggered_prop_ids={}

Any ideas on a work around?

Thanks!

Describe your context

dash==2.17.0
dash_core_components==2.0.0
dash_html_components==2.0.0

Describe the bug

In the example below, the callback using MATCH is triggered for all matching components, even ones that haven’t changed and don’t need updating.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State, MATCH, ALL

app = dash.Dash(__name__, suppress_callback_exceptions=True)

app.layout = html.Div(
    [
        html.Button("Add Filter", id="dynamic-add-filter", n_clicks=0),
        html.Div(id="dynamic-dropdown-container", children=[]),
    ]
)


@app.callback(
    Output("dynamic-dropdown-container", "children"),
    Input("dynamic-add-filter", "n_clicks"),
    State("dynamic-dropdown-container", "children"),
)
def display_dropdowns(n_clicks, children):
    new_element = html.Div(
        [
            dcc.Dropdown(
                id={
                    "type": "dynamic-dropdown",
                    "index": n_clicks,
                },
                options=[
                    {"label": i, "value": i} for i in ["NYC", "MTL", "LA", "TOKYO"]
                ],
                style={"width": "200px", "display": "inline-block"},
            ),
            dcc.Input(
                id={
                    "type": "dynamic-input",
                    "index": n_clicks,
                },
                type="number",
                style={"width": "200px", "display": "inline-block"},
            ),
            html.Div(
                id={
                    "type": "dynamic-output",
                    "index": n_clicks,
                }
            ),
        ]
    )
    children.append(new_element)
    return children


@app.callback(
    Output({"type": "dynamic-input", "index": MATCH}, "value"),
    Input({"type": "dynamic-dropdown", "index": MATCH}, "value"),
)
def set_initial_value(city):
    values = {
        "NYC": 10,
        "MTL": 20,
        "LA": 30,
        "TOKYO": 40,
        None: None,
    }
    return values[city]


@app.callback(
    Output({"type": "dynamic-output", "index": MATCH}, "children"),
    Input({"type": "dynamic-dropdown", "index": MATCH}, "value"),
    State({"type": "dynamic-dropdown", "index": MATCH}, "id"),
)
def display_output(value, id):
    return html.Div("Dropdown {} = {}".format(id["index"], value))


if __name__ == "__main__":
    app.run_server(debug=True)

Example:

Select a value from the dropdown. The input next to it is populated with an initial value
Change that value (e.g. just increment it by 1)
Click “Add Filter”. The new row is added correctly, but the first input is reset to its initial value even though the first dropdown has not changed.

Expected behavior

The set_initial_value function should only be called for components that have changed. It seems to be called for all matching components even if only one of them has changed.
"

Although this can be avoided by using prevent_initial_call=True in the callback, I believe that this is still unexpected behavior.
There may also be a relation to Issue #2371 as well, in which a similar confusion around pattern-matching callbacks can be found.