Repository navigation
docs(useCollator): add a locale-aware name sort example block - #9510
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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]
| { | ||
| "name": "example-use-collator-locale-aware-name-sort", | ||
| "path": "examples/use-collator/locale-aware-name-sort", | ||
| "aliases": [] | ||
| }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]
PR Analysis Report🔎 Preview ·
|
Reader impact
A builder reading the
useCollatordocs 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, andastryx template useCollatorHookUsage <path>copies it.Source of truth
useCollatorand its HookDoc (packages/core/src/i18n/useCollator.ts,useCollator.doc.mjs).architecture:knowledge-contractsINV28.Correction
Adds
blocks/components/Hooks/useCollatorHookUsage(exampleFor: 'useCollator'). AnInternationalizationProviderwraps a list whose names are sorted withcollator.comparefromuseCollator(). A SegmentedControl switches the provider betweenenandsv-SE.The issue suggests a Table sorted from its Name header. I used a List instead, because
useTableSortableStatealready sorts any string column without a custom comparator throughuseCollator({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 fromcollator.compare. If you would rather show it in a Table anyway, I can switch it.Evidence
/components/useCollator).Ana, Åsa, Émile, emma, Örjan, oscar, ZoëAna, Émile, emma, oscar, Zoë, Åsa, Örjan.sort()givesAna, Zoë, emma, oscar, Åsa, Émile, Örjan.packages/cli/api/template/use-collator-hook-usage.test.tsx, outsideassets/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
internal/shadcn-registry/routes.lock.jsonand its sandbox route inapps/sandbox/scripts/next-export-routes.json.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, thenvitest run src/__tests__/data-extraction.test.ts src/__tests__/example-coverage.test.ts: 133 passed, 0 failed. The route lock check is clean afterUPDATE_SHADCN_ROUTE_LOCK=1added the new route.pnpm -F @astryxdesign/cli typecheck(template docs and strict): clean.eslint(strict tier) andprettier --checkon the touched files: clean.node scripts/release/changeset-coverage.mjs pr --base upstream/main --head HEAD --released v0.7.5: passes. Changeset is@astryxdesign/clipatch,[docs].pnpm testsuite.Fixes #9475