Skip to content

fix: sidebar hint — texte correct et disparition à l'ouverture - #30

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

fix: sidebar hint — texte correct et disparition à l'ouverture#30
SKOHscripts merged 1 commit into
mainfrom
claude/fix-sidebar-hint-v2

Conversation

@SKOHscripts

Copy link
Copy Markdown
Owner

Deux bugs corrigés

1. Texte affiché = clé de traduction ("app.sidebar_hint")

L'ancienne implémentation construisait l'innerHTML par concaténation JS :

h.innerHTML = '...' + "app.sidebar_hint" + '...';  // si t() échouait

Fix : l'innerHTML complet est maintenant assemblé côté Python (où t() fonctionne garantis), puis passé comme un seul string JSON :

_hint_inner = json.dumps(
    '<div class="_a">&#x2196;</div>'
    f'<div class="_t">{_html.escape(t("app.sidebar_hint"))}</div>'
)
# En JS : h.innerHTML = <_hint_inner>;  ← une seule valeur, pas de concaténation

2. La flèche ne disparaissait pas à l'ouverture de la sidebar

Les setTimeout/setInterval étaient scopés à l'iframe que Streamlit détruit à chaque re-render, perdant ainsi les event listeners.

Fix :

  • Timers stockés sur window.parent (win._sbTimer, win._sbPoll) → survivent aux re-renders
  • L'ouverture de la sidebar est détectée par polling (toutes les 400ms, on vérifie si le bouton stSidebarCollapsedControl a disparu) plutôt que par un click event qui pouvait être raté

Plan de test

  • Ouvrir l'app sans base de données
  • Attendre 20 secondes sans toucher à la sidebar
  • La flèche ↖ avec le texte "Ouvrir le menu" apparaît
  • Ouvrir la sidebar → la flèche disparaît immédiatement
  • Recharger → la flèche ne réapparaît plus (flag sessionStorage posé)

https://claude.ai/code/session_01VTBKKYLiAQ6mDPdmVhpRAT


Generated by Claude Code

Two bugs fixed:

1. Wrong text ("app.sidebar_hint" key instead of translation):
   The innerHTML was built by JS string concatenation which broke when
   hint_label was injected. Now the full innerHTML is assembled in
   Python (where t() is guaranteed to work) and passed as a single
   JSON string: h.innerHTML = <single-json-string>.

2. Arrow not dismissing on sidebar open:
   The setTimeout/setInterval were scoped to the iframe which Streamlit
   destroys on each re-render, losing the event listeners. Fixed by
   storing timers on window.parent (_sbTimer, _sbPoll) so they survive
   re-renders. Sidebar state is now detected by polling for the
   collapsed-control button disappearing rather than relying on a
   click event that could be missed.

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 26, 2026 20:43
@SKOHscripts
SKOHscripts merged commit b898c3e into main May 26, 2026
5 checks passed
@SKOHscripts
SKOHscripts deleted the claude/fix-sidebar-hint-v2 branch May 26, 2026 20:44
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