Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[BUG] dcc.Patch() wipes persistence of sibling pattern-matching elements

オープン
#3,937 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
frontend

調査の方向性

まず、Issue 内の最小の Dash アプリケーションを Dash 4.4.0 で実行し、次に dcc.Patch() が pattern-matching IDs を持つ children をどのように更新するか、また persistence がどのように復元されるかを追跡します。新しい sibling を追加したときに、既存の pattern-matched inputs のローカル persistence が保持され、無関係な persistence は変更されないことを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug P2 size: 1

Sibling of: https://github.com/plotly/dash/issues/3681
Environment

dash                 4.4.0

When patching a new element to list of elements with pattern matched ids, persistence is wiped from all sibling IDs.

Minimal example:

from dash import ALL, Dash, Input, Output, Patch, dcc, html, clientside_callback, callback

app = Dash(__name__)

def make_input(index):
    return dcc.Input(
        id={"type": "inp", "index": index},
        value="initial",
        persistence=True,
        persistence_type="local",
    )


app.layout = html.Div(
    [
        html.Button("add", id="add"),
        html.Button("clear", id="clear"),
        html.Div([make_input(0), make_input(1)], id="container"),
        html.Div(id="display"),
        html.Pre(id="storage"),
        dcc.Interval(id="local_storage_poll", interval=250),
        dcc.Input("Hello, I don't wipe", id='non-pattern-matching-id', persistence=True, persistence_type='local')
    ]
)


@callback(
    Output("container", "children"),
    Input("add", "n_clicks"),
    prevent_initial_call=True,
)
def add_input(n):
    patch = Patch()
    patch.append(make_input(n + 1))
    return patch


@callback(Output("display", "children"), Input({"type": "inp", "index": ALL}, "value"))
def show(values):
    return "|".join(values)


# Debug info, show local storage to make it easier to noticed when it's wiped
clientside_callback(
    """
    function display_persisted_vals() {
        return Object.keys(window.localStorage)
            .filter(k => k.startsWith('_dash_persistence.'))
            .map(k => k + ' = ' + window.localStorage.getItem(k))
            .join('\\n') || '(nothing persisted)';
    }
    """,
    Output("storage", "children"),
    Input("local_storage_poll", "n_intervals"),
)

# Debug helper, clear local storage to do a clean test
# (helpful after the fix when the storage doesn't wipe constantly, lol)
clientside_callback(
    """
    function clear_persistence() {
        Object.keys(window.localStorage)
            .filter(k => k.startsWith('_dash_persistence.'))
            .forEach(k => window.localStorage.removeItem(k));
        window.location.reload();
        return window.dash_clientside.no_update;
    }
    """,
    Output("clear", "n_clicks"),
    Input("clear", "n_clicks"),
    prevent_initial_call=True,
)


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

Here is a run of the minimal example app

Persistence works without a patch.
When a patch is applied persistence is wiped from siblings, but not from unrelated elements.

主要言語
Python
スター
24.4k
フォーク
2.3k
平均マージ
1日 19時間
マージ済み PR(30日)
19

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

plotly/dash のほかの issue

plotly/dash の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。