Skip to content

fix: sidebar hint en CSS pur (cause: testid disparu en Streamlit 1.57) - #33

Merged
SKOHscripts merged 1 commit into
mainfrom
claude/fix-sidebar-hint-v5
May 27, 2026
Merged

fix: sidebar hint en CSS pur (cause: testid disparu en Streamlit 1.57)#33
SKOHscripts merged 1 commit into
mainfrom
claude/fix-sidebar-hint-v5

Conversation

@SKOHscripts

Copy link
Copy Markdown
Owner

La vraie cause racine (enfin trouvée)

En inspectant le frontend compilé de Streamlit 1.57 :

"data-testid":`stSidebar`,"aria-expanded":!r

→ Le testid stSidebarCollapsedControl que toutes les versions JS précédentes interrogeaient n'existe plus dans Streamlit 1.57. Le querySelector ne trouvait jamais le bouton, donc la condition « sidebar fermée » était toujours fausse et la flèche ne s'affichait jamais.

En plus :

  • st.html() ET st.components.v1.html() rendent dans une iframe → les timers JS meurent à chaque re-render Streamlit.
  • st.components.v1.html est déprécié (supprimé après 2026-06-01) → d'où le warning récurrent.

Solution propre : CSS pur, zéro JS, zéro iframe

Injecté via st.markdown(unsafe_allow_html=True) qui rend inline dans le document principal (garde les <style>, pas d'iframe, pas de dépréciation) :

  • La <section data-testid="stSidebar"> porte aria-expanded="false" quand fermée, "true" quand ouverte (vérifié dans le source 1.57).
  • Le sélecteur body:has(section[data-testid="stSidebar"][aria-expanded="false"]) #_sb_hint n'affiche la flèche que sidebar fermée → elle disparaît instantanément à l'ouverture, sans JS.
  • animation-delay: 20s gère l'attente d'inactivité.
  • Keyframe sb-bounce pour l'animation de la flèche.

Suppression des imports json et streamlit.components.v1 devenus inutiles.

Comportement

Condition Résultat
Pas de DB (branche Python) + sidebar fermée + 20s Flèche ↖ « Ouvrir le menu » apparaît
Sidebar ouverte Flèche cachée immédiatement
DB présente Jamais affichée (hors branche)

Note : sans JS/sessionStorage, si l'utilisateur referme la sidebar et attend 20s, l'indice réapparaît — comportement voulu et cohérent.

Test

  • App sans DB, sidebar fermée → attendre 20s → flèche apparaît
  • Ouvrir sidebar → flèche disparaît
  • Plus aucun warning de dépréciation dans les logs

https://claude.ai/code/session_01VTBKKYLiAQ6mDPdmVhpRAT


Generated by Claude Code

Root cause of all prior failures: the JS queried
[data-testid="stSidebarCollapsedControl"], which does not exist in
Streamlit 1.57 — so the "sidebar closed" check was never true and the
arrow never showed. Both st.html and st.components.v1.html also render
in an iframe whose timers die on every Streamlit re-render, and
st.components.v1.html is deprecated (removed after 2026-06-01).

Replace the whole thing with pure CSS injected via st.markdown (renders
inline in the main document, keeps <style>, no iframe, no JS):
- The sidebar <section data-testid="stSidebar"> exposes
  aria-expanded="false" when collapsed; a body:has(...) selector shows
  the hint only then, so it vanishes the instant the sidebar opens.
- animation-delay:20s provides the inactivity wait; a bounce keyframe
  animates the arrow.

Drop the now-unused json and streamlit.components.v1 imports.

https://claude.ai/code/session_01VTBKKYLiAQ6mDPdmVhpRAT
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@SKOHscripts
SKOHscripts marked this pull request as ready for review May 27, 2026 05:54
@SKOHscripts
SKOHscripts merged commit 5562ad5 into main May 27, 2026
5 checks passed
@SKOHscripts
SKOHscripts deleted the claude/fix-sidebar-hint-v5 branch May 27, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants