Skip to content

fix(list): sort recommended by the base language, not the resolved locale - #225

Merged
sydevs-bot merged 5 commits into
mainfrom
claude/fix-223-regional-locale
Oct 2, 2026
Merged

sydevs-bot merged 5 commits into
mainfrom
claude/fix-223-regional-locale

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On pt-BR or en-AU, recommended promotes a class in the viewer's own language again.
  • DynamicEventsList passes useLocale().languageCode — the base subtag — instead of the resolved locale.
  • sortEvents and calculateOrder are untouched. The defect was which of two in-scope values the call site picked.

Changes

  • src/components/organisms/EventsList/DynamicEventsList.tsx — passes languageCode; the memo dep follows it.
  • src/components/organisms/EventsList/DynamicEventsList.test.ts — new. Pins that argument against the source.
  • src/lib/shape/sort.test.ts — one case: a regional tag matches no event, so distance decides alone.
  • CHANGELOG.md — a Fixed entry. See the judgement call below.

Preview

No Ladle link: the ordering is driven by the resolved locale and the fetched set, neither of which a story exercises.

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm test:run — 125 files, 1619 tests.
  • Targeted specs: 2. Each was proven red at the site that causes it, then restored — the call-site pin with locale passed again, with the call renamed, and with a fourth argument appended; the sort.test.ts case with the tag narrowed inside calculateOrder, and with the language penalty removed. The call-site pin was also proven to survive the call wrapped across lines with a trailing comma.
  • Build: N/A — CI runs it.

Manual verification

  1. pnpm dev, then ?locale=pt-BR&sort=recommended over a search returning Portuguese and non-Portuguese classes. The Portuguese ones now outrank equidistant foreign-language ones.
  2. Repeat with ?locale=en-AU over a mixed English/non-English search.
  3. Confirm a plain ?locale=en search is unchanged.

Whether this is live right now depends on whether SahajCloud's sy-atlas-config.availableLocales currently carries pt-BR or en-AU (#198).

Notes for reviewer

  • The ticket named a different line, and refactor(list): move sortEvents into src/lib/shape/sort.ts #224 is why. It put the fix at DynamicEventsList.tsx:83, narrowing i18next's singleton. refactor(list): move sortEvents into src/lib/shape/sort.ts #224 landed between filing and implementation and moved that read into useLocale(), so the fix is the argument at the call site instead. The ticket anticipated this and said to pass i18n.resolvedLanguage?.split('-')[0] rather than languageCode, to avoid also closing the unresolved-language window. That window is already closed on main: use-locale.ts:72 reads i18n.resolvedLanguage || 'en', so languageCode and a hand-rolled split are now the same value. This PR still changes one behaviour.

  • Judgement call 1 — the CHANGELOG entry. The ticket said none was needed, on the grounds that no attribute, origin or URL shape changes. CHANGELOG.md's own header says it records "visible behaviour", and a visitor on two of the offered locales sees a different order, so I added one. Drop the entry if you read that charter more narrowly.

  • Judgement call 2 — the call-site spec survives, repaired, and its thread is still open. Review asked for it to be dropped in favour of a sort.test.ts case. That case is now in, and it is the better assertion: it pins a value rather than a token. It cannot replace the call-site pin, though, because only that pin reds when the call passes locale again, and that regression is fix(list): recommended ignores language on a regional locale #223 itself. So both ship. The pin no longer asserts a token at a position: whitespace and a trailing comma are normalised away and the call text is matched with toContain, as href.test.ts does, so sortEvents(events, order, locale, languageCode) now fails where it used to pass. It does pin one spelling — an inline useLocale().languageCode would red it, loudly and legibly. Delete the file if you would rather this fix ship with only the value contract, as the four sibling languageCode call sites do.

  • Worth a second look, not filed: src/lib/distance.ts:12 matches the whole resolved locale against {'en-us','en-gb'} — the mirror of this defect, since preferredLocale narrows a requested en-GB to en where only en is offered. distance.test.ts:18-22 pins usesMiles('en') === false deliberately, so that is a product decision to re-open rather than a bug, and I left it alone. Review reached the same file independently and read it as feat(event): redesign event display & registration surfaces #52's miles branch being unreachable.

Detail

Why the call site rather than sortEvents. The first version of this branch narrowed inside sortEvents, because that is the only shape the node lane can pin directly. Three review lenses and docs/rules/i18n-and-state.md all pointed the other way:

  • The rules doc names useLocale().languageCode as the base-subtag accessor, under Language — "an event's spoken language in a filter" is the same comparison calculateOrder makes.
  • EventChips.tsx:43, Map.tsx:216 and use-turnstile.ts:155 already take languageCode. DynamicEventsList was the only one reaching for locale.
  • sort.ts:71 states the module "stays free of React and i18n". Parsing a BCP-47 tag is i18n knowledge, and the first version had to reword that very comment to fit.
  • Widening sortEvents to "pass me either kind, I'll cope" hides which kind a caller holds — the shape the bug arrived in.

The two specs together buy back the coverage that move costs: sort.test.ts says what the parameter means, the call-site pin says which value reaches it.

Fixture pre-mortem. The claim the fix rests on is that an event's languages[0] is always an ISO 639-1 two-letter code, and that exactly two offered locales are regional. Verified against SahajCloud main: src/collections/Events/Events.ts:215 builds the languages select from getLanguageOptions(), which is ISO6391.getAllCodes() (src/lib/locales/languageOptions.ts:18); src/lib/locales/index.ts:13-32 lists nineteen LOCALES, of which pt-BR and en-AU are the only regional tags.

Not narrowing the event's side would be dead code for the same reason.

Security review: skipped — no changed path matches securityReview.triggerPattern, and no added line under src/ matches its content pattern.

Docs sync: checked, nothing stale. docs/rules/i18n-and-state.md already names useLocale().languageCode as the base-subtag accessor for an event's spoken language, which is what this fix now honours.

Dismissed review findings: hoisting a const above a switch and trimming two test cases both applied to the first version of the branch and no longer exist in the diff. The comment and CHANGELOG findings from the latest review were adopted; the request to delete the call-site spec was not, for the reason in judgement call 2, and that thread is left open.

Closes #223

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

…cale

i18next resolves to a regional tag wherever one carries the bundle, and two of
SahajCloud's nineteen LOCALES are regional: `pt-BR` and `en-AU`. On either of
them `recommended` compared that tag against an event's `languages[0]`, which
is always an ISO 639-1 two-letter code — the `languages` select is built from
`getLanguageOptions()` and offers nothing else. No event matched, so the x2
wrong-language penalty landed on all of them. Being uniform it then cancelled
out of the ordering, and `recommended` silently went language-blind: a local
class was no longer promoted over an equidistant foreign-language one.

`useLocale()` already publishes both shapes, and `languageCode` is the base
subtag `docs/rules/i18n-and-state.md` names for exactly this comparison —
`EventChips`, `Map` and `use-turnstile` all take it. `DynamicEventsList` was
the one call site reaching for `locale` instead. `sortEvents` and
`calculateOrder` keep the `language` parameter they already had, so the pure
module gains no knowledge of BCP-47 tag shapes.

Both in-scope values are strings, so `sortEvents` cannot tell them apart and
no pure spec can see which one a call passes. `DynamicEventsList.test.ts`
therefore pins the argument against the source, as `responsive.test.ts` and
`href.test.ts` pin their own call sites. It goes red both when the call passes
`locale` again and when the call stops matching at all.

Closes #223

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: f1e356f
Status: ✅  Deploy successful!
Preview URL: https://c6676af3.sahajatlas.pages.dev
Branch Preview URL: https://claude-fix-223-regional-loca.sahajatlas.pages.dev

View logs

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 22, 2026
@sydevs-bot

sydevs-bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 18:44Z resolve-conflicts · attempt 1 · session · done
  • 18:44Z resolve-conflicts · attempt 1 · session
  • 16:55Z address-review · attempt 1 · session · done
  • 16:55Z address-review · attempt 1 · session
  • 16:48Z adversarial-review · attempt 1 · session

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

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 Adversarial review

One line of behaviour, and it is the right line. languageCode is the repo's base-subtag accessor, sortEvents is untouched, and the ticket's open question is moot: use-locale.ts:72 returns resolvedLanguage || 'en', so the split it asked for is the same value. The diff is no bigger than the problem. The one real question is the source-scraping spec.

Findings — three consider, each on its thread: the spec pins a token, the comment restates the diff, the CHANGELOG entry sits above Added.

Worth a ticket, not this PR. lib/distance.ts:12 is the same defect one step on: preferredLocale returns only offered locales, and neither en-US nor en-GB is offered, so MILE_LOCALES never matches — #52's miles branch is unreachable.

Checked. #223, the diff, and in full: the call site, sort.ts + spec, use-locale.ts, i18n-options.ts, distance.ts. On SahajCloud main: 19 LOCALES, pt-BR and en-AU the only regional ones; Events.ts:215 builds languages from ISO 639-1 codes. sortEvents has one caller.

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


Generated by Claude Code

Comment thread CHANGELOG.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 22, 2026
`docs/rules/code-comments.md` keeps the why, not the narration. The three added
lines restated the diff and the spec beside it. The one constraint a fresh reader
cannot derive is that an event's language is an ISO 639-1 base code, so the tag has
to be narrowed before it reaches `sortEvents`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The call-site spec read `.at(-1)` over a `[^)]*` match, so it asserted a token at a
position rather than a fact. `sortEvents(events, order, locale, languageCode)` passed
it, and an argument carrying a `)` broke the match. It now normalises whitespace and a
trailing comma away and pins the call text with `toContain`, the idiom `href.test.ts`
already uses: the wrapped form passes, the four-argument form fails.

A source pin still cannot say what the two values MEAN, so `sort.test.ts` gains the
case that can. Under `pt-BR` a `pt` event counts as foreign, the penalty lands on every
event and cancels, and distance alone decides — what #223 shipped. The same set under
`pt` ranks the local class first, so the pair shows the tag shape moving the ordering
rather than the fixtures.

Proven red before restoring: the call-site spec with `locale` passed again, with the
call renamed, and with a fourth argument; the `sort.test.ts` case with the tag narrowed
inside `calculateOrder` and with the penalty removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Every other group run in the file reaches Fixed after Added, and the header claims
Keep a Changelog order. The new group sat above Added instead. A pure relocation —
the entry's text is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 22, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The session for this item did not finish after 3 attempts. I have stopped retrying. A comment, a verb, or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Three review threads, all answered. Head is 0d519c5, pushed.

Adopted. The call-site comment is cut to your one line (9a722d1). The CHANGELOG group moved below Added (0d519c5) — a pure relocation, entry text unchanged.

Adopted in part, thread left open. The call-site spec: your sort.test.ts case is in, and it is the better assertion. The pin no longer reads a token at a position — whitespace and a trailing comma are normalised away and toContain matches the call text, so sortEvents(events, order, locale, languageCode) now fails. The file stays because only it reds when the call passes locale again, which is #223 itself. Delete it if you still disagree.

Lean gate green — 125 files, 1619 tests. Each new assertion was proven red at the site that causes it before restoring. Body refreshed with the live branch preview.

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


Generated by Claude Code

@sydevs-bot
sydevs-bot marked this pull request as ready for review September 22, 2026 17:07
@sydevs-bot
sydevs-bot requested a review from Ardnived September 22, 2026 17:07
GitHub reported the PR conflicting. The one conflict was the CHANGELOG's
link-reference list: #223 here and #234 on main both appended a definition
after #220. Both entries exist in the file, so both definitions stay, in
number order. No entry text on either side was touched.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. One conflict: the CHANGELOG link-reference list, where #223 and #234 each appended a definition after #220. Both entries are in the file, so both definitions stay. No entry text moved.

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


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 1, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit 5c85fda Oct 2, 2026
25 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-223-regional-locale branch October 2, 2026 01:26
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

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

3 participants