[BUG] dcc.Dropdown: virtualized list keeps the height measured at opening when options grow while the menu is open

未關閉
#4,131 1 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@KoolADE85 已經在處理了。

開始於 2026年11月9日。

評估

這個 Issue 還沒有評估資料。

描述

bug P3 size: 1

Describe your context

dash                 4.5.0

Reproduced in headless Chromium (Playwright); first seen by our users on dash 4.4.1.

Describe the bug

A multi dcc.Dropdown whose options are updated by a callback while its menu is open keeps the list height it measured when the menu opened. If the menu opens while the options are few (here 1) and the callback then brings back many (here 300), the virtualized list stays one row tall (34 px) and the user has to scroll inside a single row. Closing and opening the menu again shows it at the normal height.

This happens with cascading filters: an item is chosen, the callback narrows the options to it, the user clears it with the × and opens the menu again before the callback has returned all the options.

The cause seems to be in OptionsList (components/dash-core-components/src/utils/optionRendering.tsx): the container is measured once, in a useLayoutEffect with an empty dependency array, and listHeight = Math.min(measuredHeight, options.length * defaultOptionHeight). With one option the measured height is one row, and it is never measured again when options grows.

Minimal example

import time
from dash import Dash, Input, Output, dcc, html

ALL = [f"item-{i:03d}" for i in range(300)]

app = Dash(__name__)
app.layout = html.Div(
    [dcc.Dropdown(id="dd", options=ALL, multi=True, placeholder="Pick an item")],
    style={"width": 400, "padding": 40},
)


@app.callback(Output("dd", "options"), Input("dd", "value"))
def narrow(value):
    # like a cascading filter: once an item is chosen only it is offered;
    # cleared, all 300 come back (the server takes a moment)
    time.sleep(0.5)
    return value if value else ALL


if __name__ == "__main__":
    app.run(port=8077, debug=False)

Steps:

  1. open the menu, pick item-007, close the menu (the options become ["item-007"]);
  2. click the × (Clear selection) and open the menu at once, before the callback returns;
  3. wait for the 300 options to come back.

Measured with Playwright on .dash-dropdown-content .dash-options-list-virtualized:

State list height content height
menu opened with 300 options 124 px 10494 px
step 3: menu opened with 1 option, 300 options back 34 px 10500 px
menu closed and opened again 124 px 10494 px

Expected behavior

The list height follows the options: when options changes while the menu is open, the list is measured again (for example the layout effect depending on options.length, or measuredHeight reset when the options change), so 300 options show at the normal height without closing and reopening the menu.

We work around it client-side by closing and reopening a menu whose virtualized list is shorter than three rows while its content is taller, which is what users did by hand.

Image Image
主要語言
Python
星號
24.5k
分支
2.3k
平均合併
3 天 7 小時
30 天內合併 PR
30

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

plotly/dash 的其他 Issue

查看 plotly/dash 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。