Course home: clearing `start_course` adds a history entry

Aperta Adatta ai principianti
#2,265 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
80/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, react
Ambito
frontend

Direzione di ricerca

Inizia in src/course-home/outline-tab/OutlineTab.jsx intorno alle righe 102-117: l'effetto che rimuove ?start_course=1 dopo l'invio di enrollment.email.clicked.startcourse; la chiamata passa replace: true dentro l'oggetto To invece del secondo argomento options. Confronta con WeeklyLearningGoalCard.jsx, che usa ancora history.replace per weekly_goal. Leggi la documentazione v6 di useNavigate su options.replace, poi controlla i test esistenti di outline-tab per la configurazione del router e aggiungi un caso che asserisce che la navigazione di pulizia era un replace, non un push. Fatto significa che Indietro lascia la home del corso dopo essere arrivati con ?start_course=1, l'evento scatta una volta, e quel test fallisce rispetto alla chiamata attuale.

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

Descrizione

Clearing start_course adds a history entry. When a learner opens the course home from the enrollment email, the outline tab sends the enrollment.email.clicked.startcourse event and takes ?start_course=1 out of the address. It does that with a new history entry, where it means to replace the current one. Back then returns to the ?start_course=1 address, the event is sent a second time, and the learner is moved forward again. It has been this way since #1128 (2023-10), the React Router v6 upgrade.

A test of the same call shows the router recording the navigation as a push. What Back does follows from that and has not been watched in a browser.

Status (2026-11-18): fixed in the frontend-base version of Learning, the package under frontend-base/ on the frontend-base branch, by #2252. The frontend-build and frontend-platform version under src/ still has it.

[!NOTE]
This issue was written by Claude (Claude Code) and reviewed before posting.

Claude Plan

Mechanism

  • OutlineTab.jsx clears the parameter with navigate({ pathname, search, replace: true }): replace is a key of the first argument.

  • React Router's navigate takes replace in its second argument. From the useNavigate page of the v6 documentation:

    Either pass a To value (same type as <Link to>) with an optional second options argument

    and, under options.replace:

    Specifying replace: true will cause the navigation to replace the current entry in the history stack instead of adding a new one.

  • A To object carries a pathname, a search string and a hash. A replace key in it is not read, so the call navigates with the default, a push.

History

  • #1128 (2023-10-05) turned history.replace({ search: currentParams.toString() }) into the navigate call and put replace: true in the first argument (the commit).
  • The weekly goal card's cleanup of weekly_goal, in WeeklyLearningGoalCard.jsx, still calls history.replace and is not affected.

What a learner sees

After arriving with ?start_course=1, the history holds two entries for the course home: the address with the parameter, and the one without. Back goes to the first. The effect runs again there, sends enrollment.email.clicked.startcourse again and adds the clean address again. Each press of Back repeats that, so Back does not leave the page and the event is counted once per press.

Fix

navigate({ pathname, search }, { replace: true }), with a case that fails when the cleanup adds an entry. #2252 does this in the frontend-base package: its case asserts that the router's last navigation was a replace, and it fails with the call as it is here, the router reporting a push.

Acceptance

  • After arriving with ?start_course=1, Back leaves the course home
  • enrollment.email.clicked.startcourse is sent once
  • A test fails if the cleanup adds a history entry
Lingua principale
JavaScript
Stelle
71
Fork
341
Merge medio
4g 18h
PR unite (30g)
20

Preparare l'ambiente

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 openedx/frontend-app-learning

Tutte le issue di openedx/frontend-app-learning

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.