Select: custom `popupRender` content stays stale after the dropdown closes, with no way to opt out

Aperta
#1,261 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Start in the trigger package: read src/Popup/PopupContent.tsx (the React.memo comparing next.cache) and the cache: !open && !fresh / CSSMotion removeOnLeave: false setup in src/Popup/index.tsx, then follow how BaseSelect builds the fixed prop list for SelectTrigger and dumps everything else into restProps for SelectInput. Deciding which prop name to expose (destroyOnHidden vs plumbing fresh/autoDestroy) is an open API question the thread has not settled. Done means the prop reaches the trigger from Select and the hidden .ant-select-dropdown re-renders, verified by a test that reads .preview after Esc.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment

  • @rc-component/select 1.12.0 (same behavior through antd 6.7.2), React 19

What happens

When popupRender renders UI that is derived from component state, that UI is frozen once the dropdown closes. Example: a two-column dropdown where the left column is the option list and the right column is a preview panel that follows the currently hovered option.

  1. open the dropdown, hover option B → preview panel shows B
  2. close with Esc (no selection) → the select value is unchanged, state is reset
  3. the hidden .ant-select-dropdown still shows B's preview; later state changes do not reach it either
  4. reopening recomputes correctly, so this is invisible in the UI — but DOM inspection, e2e assertions and a11y/audit tooling read stale content

Where it comes from (traced, not guessed)

  • @rc-component/trigger src/Popup/PopupContent.tsx: React.memo(({ children }) => children, (_, next) => next.cache), with cache: !open && !fresh set in src/Popup/index.tsx. Closed popup children are intentionally not re-rendered.
  • src/Popup/index.tsx renders CSSMotion with removeOnLeave: false, so the popup DOM is kept (class -hidden) rather than unmounted. Also intentional for perf.

So the trigger layer already has the knobs needed (fresh, autoDestroy), but BaseSelect passes SelectTrigger a fixed prop list (visible, popupElement, popupRender, popupAlign, ...). Everything else lands in restProps and goes to SelectInput, so fresh / autoDestroy set on Select never reach the trigger. Neither prop is exposed by Select either.

Minimal repro

const [hover, setHover] = useState('a');

<Select
  open
  options={[{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }]}
  optionRender={(opt) => (
    <div onMouseEnter={() => setHover(String(opt.value))}>{opt.label}</div>
  )}
  popupRender={(menu) => (
    <div style={{ display: 'flex' }}>
      <div>{menu}</div>
      <div className="preview">{hover === 'b' ? 'Preview B' : 'Preview A'}</div>
    </div>
  )}
/>

Hover "B", press Esc, then read document.querySelector('.preview').textContent → still Preview B.

Expected

Either the hidden popup content stays in sync with the current state, or there is an explicit switch for it.

Proposal

  • expose destroyOnHidden (matching the antd v6 naming used by Modal/Tabs/Drawer) on Select, or
  • at minimum pass fresh / autoDestroy through to SelectTrigger so callers can opt in.

Not asking to change the default (caching and keeping the DOM is clearly a perf choice) — only to make it controllable.

Lingua principale
TypeScript
Stelle
940
Fork
485
Merge medio
8h 4m
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di react-component/select

Tutte le issue di react-component/select

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.