Skip to content

fix(list): recommended ignores language on a regional locale #223

Closed

Description

@sydevs-bot

Summary

recommended's wrong-language penalty compares i18next's resolved language against an event's own language code. The resolved value can be a regional tag, while an event's is always a two-letter ISO 639-1 base code. So on a regional locale no event matches, the ×2 lands on every one of them, and — being uniform — it cancels out of the ordering entirely. recommended silently degrades to language-blind: a local class is no longer promoted over an equidistant foreign-language one.

⚠ This ticket described #222's proposed end state, not main

Every file and signature in the original body came from that ticket's plan. #222 is open and itself blocked, so none of it exists on main (d69b28a):

Premise as filed On main
calculateOrder is in src/lib/shape/sort.ts src/components/organisms/EventsList/DynamicEventsList.tsx:46. sort.ts holds only the ?sort= codec — no calculateOrder, no sortEvents
language is passed from the call site, as useLocale().resolvedLanguage Nothing is passed. sortEvents reads the singleton: const language = i18n.resolvedLanguage (:83). And useLocale() has no resolvedLanguage key — it returns locale and languageCode (src/hooks/use-locale.ts:106-114)
sortEvents' third argument sortEvents(events, order) — two parameters (:74). A third exists only in #222's proposal
src/lib/shape/sort.test.ts Does not exist. The spec is src/components/organisms/EventsList/DynamicEventsList.sort.test.ts
"The fix is which value the call site passes, not the comparison" There is no call site to change. On main the fix is the read at :83

The bug survives all of this intact. Only the fix's location moved.

Approach

One line, at the single read — src/components/organisms/EventsList/DynamicEventsList.tsx:83:

const language = i18n.resolvedLanguage?.split('-')[0]

calculateOrder (:46) already takes language: string | undefined as a parameter and needs no change. The regional tag enters at that one read and nowhere else, so narrowing it there is the whole fix.

Do not narrow the event's side as well. SahajCloud constrains it already: languages is a select whose options are getLanguageOptions() — every ISO 639-1 two-letter code and nothing else (SahajCloud src/collections/Events/Events.ts:215, SahajCloud src/lib/locales/languageOptions.ts:18). An event's code cannot be regional, so a symmetric narrowing would be dead code.

How the regional tag reaches resolvedLanguage

  1. preferredLocale (src/config/i18n-options.ts:103) returns the regional tag two ways: an exact match at :111 (a pt-BR request), and the regional-variant fallback at :118 (a plain pt request, where pt-BR is the only Portuguese offered).
  2. applyBundle (src/config/locale.ts:110-114) adds the bundle under that exact tag, then calls changeLanguage with it.
  3. i18next resolves to the first tag in the hierarchy carrying resources — pt-BR, because that is the bundle just added. Not pt.

The regional tags are a closed set, and there are two

availableLocales selects from SahajCloud's LOCALES (SahajCloud src/lib/locales/index.ts:13-32, wired through getLocaleOptions() in SahajCloud src/fields/availableLocalesField.ts). Exactly two of the nineteen are regional:

  • pt-BR (Brazilian Portuguese)
  • en-AU (Australian English)

Every other offered locale is a base tag and is unaffected.

⚠ The filed body ruled out en-US correctly, then drew the wrong conclusion from it. Nothing publishes en-US, so preferredLocale narrows it to en and the penalty is right. But en-AU is published, so an Australian viewer pays the penalty on every English event — the same failure, in English, on a tag the CMS already offers. A plain en viewer stays safe either way: preferredLocale's exact match at :111 takes en before any variant.

The spec — and why the obvious assertion cannot fail

⚠ A set where every event is penalised cannot show this bug. The ×2 is a uniform scalar there, so the order is identical with and without it. The failure is only visible in a mixed set: events in the viewer's base language alongside events in another. Cover it in src/components/organisms/EventsList/DynamicEventsList.sort.test.ts.

The language must vary per case, and the existing vi.mock at :11 is module-scoped. Make it mutable — sortEvents reads the property at call time, so reassigning it between cases works:

const i18nMock = vi.hoisted(() => ({ default: { resolvedLanguage: 'en' } }))
vi.mock('@/config/i18n', () => i18nMock)

Build each pair by spreading mockEventSlim (src/mocks/events.ts:71) and varying only id, distance and languages. Every other factor — soon ×0.5, online ×1.5, unverified ×1.5 — is then common to the pair and cancels, so the arithmetic below is just distance × the language factor.

Case resolvedLanguage Events Before the fix After the fix
Regional match (goes red without the fix) pt-BR pt at 10, fr at 6 20 vs 12 → fr, pt 10 vs 12 → pt, fr
Penalty still lands (goes red without the fix) pt-BR pt at 11, fr at 10 22 vs 20 → fr, pt 11 vs 20 → pt, fr
Base tag unchanged (a pin, not a regression test — it passes either way) en en at 10, fr at 6 10 vs 12 → en, fr unchanged

The three existing cases at :23, :32 and :44 use mockEventSlim.languages = ['en'] against a mocked 'en', so they carry no language penalty and are unaffected.

Acceptance criteria

  • DynamicEventsList.tsx:83 narrows the resolved language to its base subtag before it reaches calculateOrder.
  • Under ?sort=recommended on pt-BR or en-AU, an event whose languages[0] is the matching base code (pt, en) pays no wrong-language penalty.
  • An event in a genuinely different language still pays the ×2.
  • calculateOrder's signature and its other three factors are untouched.
  • DynamicEventsList.sort.test.ts covers all three cases in the table above, with the language varied per case.
  • pnpm lint, pnpm typecheck, pnpm test:run pass.

Verification checklist

  • pnpm test:run.
  • Revert the .split('-')[0] at :83 and confirm the first two table rows go red. A case whose events are all in one non-matching language stays green either way — that is the trap this checks for (docs/testing.md, "A regression spec is not finished until it has FAILED").
  • Confirm the third row stays green both with and without the fix, and keep it labelled as a pin rather than a regression case.
  • pnpm dev, then ?locale=pt-BR&sort=recommended over a search returning both Portuguese and non-Portuguese classes: the Portuguese ones now outrank equidistant foreign-language ones. Repeat with ?locale=en-AU over a mixed English/non-English search.

Open questions

  • Leave the unresolved-language window alone, or close it here? i18n.resolvedLanguage is undefined before i18next resolves, and undefined != 'en' penalises everything — uniformly, so again it cancels. ?.split('-')[0] preserves that exactly. Passing useLocale().languageCode instead would substitute 'en' (use-locale.ts:72,109) and quietly change that window too. Recommended: keep ?.split(), so this ticket changes one behaviour. refactor(list): move sortEvents into src/lib/shape/sort.ts #222 already records the undefined case.

Notes

Related

🤖 Written by the sydevs autonomous loop — see what this is

Activity

  1. added theissue type on Sep 22, 2026
  2. added
    proposal
    bot:working
    and removed on Sep 22, 2026
  3. sydevs-bot commented on Sep 22, 2026

    @sydevs-bot
    ContributorAuthor

    🤖 no session running

    recent dispatches
    • 16:32Z implement · attempt 1 · session · done
    • 16:32Z implement · attempt 1 · session
    • 04:15Z revise · attempt 1 · session · done
    • 04:15Z revise · attempt 1 · session

    Written by the sydevs dispatcher. Sessions never edit this comment.

  4. changed the title [-]fix(list): the recommended sort penalises every event in a regional locale[/-] [+]fix(list): recommended ignores language on a regional locale[/+] on Sep 22, 2026
  5. sydevs-bot commented on Sep 22, 2026

    @sydevs-bot
    ContributorAuthor

    Revised against main. The bug is real. Every file and signature in the filed body came from #222's plan, unmerged.

    Corrections

    • calculateOrder is at DynamicEventsList.tsx:46, not lib/shape/sort.ts. The language is read off the i18next singleton at :83, not passed. sortEvents takes two arguments, not three. The named spec file does not exist.
    • The effect is the opposite of "penalises every event". The ×2 is uniform, so it cancels: recommended goes language-blind.
    • en-AU is published. The body ruled out en-US, then concluded English was safe. SahajCloud's LOCALES carries two regional tags, pt-BR and en-AU.
    • Do not narrow the event's side. SahajCloud's languages select offers ISO 639-1 two-letter codes only.
    • An ordering assertion over a single-language set cannot fail here. The body carries three that can.

    Retitled to name the effect. Same type and scope.

    Not blocked. It lands on main today, and landing it first answers #222's open question.

    @sydevs-bot implement starts work.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  6. added and removed
    bot:working
    on Sep 22, 2026
  7. moved this from Proposed to Revising in SYDevelopers Technical Roadmapon Sep 22, 2026
  8. Ardnived commented on Sep 22, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  9. added
    bot:working
    and removed
    proposal
    on Sep 22, 2026
  10. moved this from Revising to Approved in SYDevelopers Technical Roadmapon Sep 22, 2026
  11. removed
    bot:working
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions