Repository navigation
Description
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
preferredLocale(src/config/i18n-options.ts:103) returns the regional tag two ways: an exact match at:111(apt-BRrequest), and the regional-variant fallback at:118(a plainptrequest, wherept-BRis the only Portuguese offered).applyBundle(src/config/locale.ts:110-114) adds the bundle under that exact tag, then callschangeLanguagewith it.- i18next resolves to the first tag in the hierarchy carrying resources —
pt-BR, because that is the bundle just added. Notpt.
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:83narrows the resolved language to its base subtag before it reachescalculateOrder. - Under
?sort=recommendedonpt-BRoren-AU, an event whoselanguages[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.tscovers all three cases in the table above, with the language varied per case. -
pnpm lint,pnpm typecheck,pnpm test:runpass.
Verification checklist
-
pnpm test:run. - Revert the
.split('-')[0]at:83and 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=recommendedover a search returning both Portuguese and non-Portuguese classes: the Portuguese ones now outrank equidistant foreign-language ones. Repeat with?locale=en-AUover a mixed English/non-English search.
Open questions
- Leave the unresolved-language window alone, or close it here?
i18n.resolvedLanguageisundefinedbefore i18next resolves, andundefined != 'en'penalises everything — uniformly, so again it cancels.?.split('-')[0]preserves that exactly. PassinguseLocale().languageCodeinstead 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 theundefinedcase.
Notes
- Not blocked. This lands on
maintoday as the one-line change above. refactor(list): move sortEvents into src/lib/shape/sort.ts #222 is a refactor that moves the same read, and is itself blocked by feat(widget): badge unverified listings on the event page #220. - Land this first. refactor(list): move sortEvents into src/lib/shape/sort.ts #222's byte-identical criterion then measures against the corrected
main, and its open question ("keep theen-USquirk, or fix it here?") is answered: already fixed, keep the base narrowing. If refactor(list): move sortEvents into src/lib/shape/sort.ts #222 somehow lands first, the change becomessortEvents' third argument — passi18n.resolvedLanguage?.split('-')[0], notlanguageCode, per the open question above. - Which locales are offered is an operator's decision, held in SahajCloud's
sy-atlas-config.availableLocalesand read at runtime (feat(i18n): source translations and the language set from SahajCloud #198). Whether this is live right now depends on whether that row carriespt-BRoren-AU. - No host-facing contract change: nothing here is observable through
<sahaj-atlas>'s attributes, origins or URL shape, sodocs/embedding.mdandCHANGELOG.mdstay untouched. - Every claim above is read from source. This run had no
node_modules, so no spec was executed and the orderings in the table are derived, not measured.
Related
- refactor(list): move sortEvents into src/lib/shape/sort.ts #222, feat(widget): badge unverified listings on the event page #220, feat(i18n): source translations and the language set from SahajCloud #198
🤖 Written by the sydevs autonomous loop — see what this is
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Hold Until
Projects
- StatusShow more project fieldsDone
Activity
sydevs-bot commentedon Sep 22, 2026
🤖 no session running
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.
[-]fix(list): the recommended sort penalises every event in a regional locale[/-][+]fix(list): recommended ignores language on a regional locale[/+]sydevs-bot commentedon Sep 22, 2026
Revised against
main. The bug is real. Every file and signature in the filed body came from #222's plan, unmerged.Corrections
calculateOrderis atDynamicEventsList.tsx:46, notlib/shape/sort.ts. The language is read off the i18next singleton at:83, not passed.sortEventstakes two arguments, not three. The named spec file does not exist.recommendedgoes language-blind.en-AUis published. The body ruled outen-US, then concluded English was safe. SahajCloud'sLOCALEScarries two regional tags,pt-BRanden-AU.languagesselect offers ISO 639-1 two-letter codes only.Retitled to name the effect. Same type and scope.
Not blocked. It lands on
maintoday, and landing it first answers #222's open question.@sydevs-bot implementstarts work.🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
Ardnived commentedon Sep 22, 2026
@sydevs-bot implement
fix(list): pin the sort contract by value, not by argument position
Merge origin/main into claude/fix-223-regional-locale