Skip to content

fix(learning): reload open roadmap on language change - #102

Open
zafopyss wants to merge 2 commits into
Derssa:mainfrom
zafopyss:fix/roadmap-language-switch
Open

zafopyss wants to merge 2 commits into
Derssa:mainfrom
zafopyss:fix/roadmap-language-switch

Conversation

@zafopyss

Copy link
Copy Markdown

Summary of Changes

Fixes #101

An open roadmap kept its original language after the UI language was switched, while the rest of the UI and the catalogue switched correctly. openRoadmap was only called on card click or panel mount, so nothing reloaded the roadmap when i18n.language changed.

  • LearningPanel now owns useRoadmaps() (single fetch on mount) and passes the catalogue state to RoadmapCatalog as a prop. The catalogue unmounts while a roadmap is open, so the list has to live one level up.
  • A new effect in LearningPanel reopens the open roadmap in its translation when the UI language changes. Languages are compared on the base subtag (fr-FR matches fr), same convention as filterByUiLanguage.
  • If no translation exists for the new language (e.g. imported roadmaps), the open roadmap stays as is. No request is sent, so no 404 from the exact (id, language) match on the backend.

Behavior notes:

  • Progress is keyed by project and roadmap id, so it is kept across the language switch.
  • Reopening goes through openRoadmap, so the player returns to the first incomplete step and displayed validation results are cleared.

Types of Changes

  • New feature / node type addition
  • Bug fix (non-breaking change resolving an issue)
  • Refactoring / structural cleanup
  • Documentation update

Verification & Testing

Automated Checks

  • Run npm run lint successfully with no errors
  • Run npm run build successfully with no compilation errors
  • Run npm test successfully (all tests pass)

Three tests added in LearningPanel.test.tsx:

  • translation exists: the roadmap is refetched with language=fr and rendered in French
  • no translation: no refetch, the roadmap stays displayed
  • fr to fr-FR: no refetch

Manual Verification

  1. Opened the Learning panel, selected a roadmap available in en and fr
  2. Switched the UI language from the topbar: the open roadmap reloads in the new language, completed steps are kept
  3. Switched back: same result in the other direction

Checklist

  • My code follows the repository's code style and lint standards
  • I have updated the documentation or instructions if necessary
  • All unit and integration tests are passing

@OthmaneZ05 OthmaneZ05 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, the overall approach looks good!This can create a race condition: if the user returns to the catalogue while the translation request is pending, the completed request can reopen the roadmap. Rapid language changes can also allow a stale response to win.

Could you invalidate or abort pending language reloads on cleanup and when closing the roadmap, and add tests for these cases?

const translation = summaries.find(
summary => summary.id === roadmap.id && summary.language.split('-')[0] === base
);
if (translation) openRoadmap(translation);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can create a race condition: if the user returns to the catalogue while the translation request is pending, the completed request can reopen the roadmap. Rapid language changes can also allow a stale response to win.
Could you invalidate or abort pending language reloads on cleanup and when closing the roadmap, and add tests for these cases?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Pending loads are now invalidated when closing the roadmap, on unmount, and when the UI language switches back to the displayed one. Added a test for each case.

…age revert

A translation load started by a UI language switch could land after the
user went back to the catalogue (reopening the roadmap) or after the
language switched back (flashing the stale translation, then reloading).
cancelPendingOpen invalidates the in-flight openRoadmap; it now runs on
close, on unmount, and when the UI returns to the displayed language.
@zafopyss
zafopyss force-pushed the fix/roadmap-language-switch branch from 96ae607 to 7577557 Compare September 24, 2026 12:31
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.

[BUG] Open roadmap keeps its original language after switching UI language

3 participants