Skip to content

docs(useCollator): add a locale-aware name sort example block - #9510

Merged
cixzhang merged 2 commits into
meta:mainfrom
MannXo:docs/9475-usecollator-example
Nov 2, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
MannXo:docs/9475-usecollator-example

Conversation

@MannXo

@MannXo MannXo commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Reader impact

A builder reading the useCollator docs has no runnable example of the hook. After this change the hook's page shows names sorted with the hook's comparator under an English and Swedish locale switch, and astryx template useCollatorHookUsage <path> copies it.

Source of truth

  • useCollator and its HookDoc (packages/core/src/i18n/useCollator.ts, useCollator.doc.mjs).
  • architecture:knowledge-contracts INV28.

Correction

Adds blocks/components/Hooks/useCollatorHookUsage (exampleFor: 'useCollator'). An InternationalizationProvider wraps a list whose names are sorted with collator.compare from useCollator(). A SegmentedControl switches the provider between en and sv-SE.

The issue suggests a Table sorted from its Name header. I used a List instead, because useTableSortableState already sorts any string column without a custom comparator through useCollator({numeric: true}) on the provider locale. A Table example would therefore look the same with the hook removed, which INV28 rules out. Here the order comes only from collator.compare. If you would rather show it in a Table anyway, I can switch it.

Evidence

  • Real Chromium (Playwright against the docsite dev server, /components/useCollator).
    • English: Ana, Åsa, Émile, emma, Örjan, oscar, Zoë
    • Swedish: Ana, Émile, emma, oscar, Zoë, Åsa, Örjan
    • A plain .sort() gives Ana, Zoë, emma, oscar, Åsa, Émile, Örjan.
  • Test (packages/cli/api/template/use-collator-hook-usage.test.tsx, outside assets/templates/ so the template viewer does not load it as a template). Asserts both orders. With .sort(collator.compare) replaced by .sort(), both tests fail.

Scope

  • This PR changes documentation only, or names every necessary generated artifact. The generated artifacts are the new block's route in internal/shadcn-registry/routes.lock.json and its sandbox route in apps/sandbox/scripts/next-export-routes.json.
  • Runtime, API, visual, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest run --project node packages/cli/api/template/use-collator-hook-usage.test.tsx apps/sandbox/src/route-manifest.test.ts: 8 passed, 0 failed.
  • vitest run --project node packages/cli/foundation/discovery packages/cli/api/template packages/cli/assets/templates internal/shadcn-registry: 1104 passed, 0 failed.
  • apps/docsite: node scripts/generate-data.mjs, then vitest run src/__tests__/data-extraction.test.ts src/__tests__/example-coverage.test.ts: 133 passed, 0 failed. The route lock check is clean after UPDATE_SHADCN_ROUTE_LOCK=1 added the new route.
  • pnpm -F @astryxdesign/cli typecheck (template docs and strict): clean.
  • eslint (strict tier) and prettier --check on the touched files: clean.
  • node scripts/release/changeset-coverage.mjs pr --base upstream/main --head HEAD --released v0.7.5: passes. Changeset is @astryxdesign/cli patch, [docs].
  • Not run: the full pnpm test suite.

Fixes #9475

A list of names sorts with the compare function from useCollator, so
accented and lowercase names land where a reader expects, and switching
the provider locale from English to Swedish moves Å and Ö after Z.

Fixes meta#9475
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 2, 2026 11:35am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 2, 2026, 11:42 AM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Nov 2, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the clear example: the order really does come from collator.compare, and the reason for using a List instead of a Table holds up. One change is needed before merge: the new block also creates the Sandbox page /templates/useCollatorHookUsage/, which apps/sandbox/scripts/next-export-routes.json doesn't list, so apps/sandbox/src/route-manifest.test.ts fails and the Sandbox build the docs deployment runs stops in verify-export.mjs (the likely cause of the failed Vercel preview). Add "/templates/useCollatorHookUsage/", in sorted order just before "/templates/useContainerRevealHookUsage/", then rerun vitest run --project node apps/sandbox/src/route-manifest.test.ts. #9509 and #9513 add hook blocks without that entry too.

[Automated review]

Comment on lines +3647 to +3651
{
"name": "example-use-collator-locale-aware-name-sort",
"path": "examples/use-collator/locale-aware-name-sort",
"aliases": []
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This registers the block's shadcn route, but the block also creates the Sandbox page /templates/useCollatorHookUsage/, and apps/sandbox/scripts/next-export-routes.json doesn't list it yet. Until it does, apps/sandbox/src/route-manifest.test.ts fails and the Sandbox build stops in verify-export.mjs with extra /templates/useCollatorHookUsage/. Add "/templates/useCollatorHookUsage/", just before "/templates/useContainerRevealHookUsage/" in that file.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks: the example does what #9475 asks, and the order really does come from collator.compare, so removing the hook breaks it. The missing Sandbox route from the last round is fixed, and the Sandbox export and docs build both pass with it. Nothing else is needed from you; a maintainer still has to approve the CI workflows for this pull request.

[Automated review]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 2, 2026
@cixzhang cixzhang closed this Nov 2, 2026
@cixzhang cixzhang reopened this Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 8ef65e5

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 3.30 MB packed (+616 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: core 5 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Nov 2, 2026
@cixzhang
cixzhang merged commit a34b886 into meta:main Nov 2, 2026
58 checks passed

This branch was successfully deployed

1 active deployment
Preview — 8ef65e59 Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(useCollator): add a minimal live example

2 participants