[BUG] dcc.Patch() wipes persistence of sibling pattern-matching elements
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 24.4k
- Fork
- 2.3k
- Merge medio
- 2g 7h
- PR unite (30g)
- 13
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo l’applicazione Dash minima nell’issue con Dash 4.4.0, quindi traccia come dcc.Patch() aggiorna children con pattern-matching IDs e come viene ripristinata la persistence. Il lavoro è completo quando l’aggiunta di un nuovo sibling preserva la persistence locale degli input esistenti con pattern matching, mentre la persistence non correlata rimane invariata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- frontend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100