chore(memory+docs): /ship-feature B3 capitalize — BDR-014/015 + LRN-017..019 + EVAL-002 + journal + TODO
Memory registry capitalization after B3 i18n FR/EN ship. - decisions.md +BDR-014 (PDF locale = render preference, store-driven, not Report schema field — dual label snapshot already carried). - decisions.md +BDR-015 (typed ImportError discriminant kind + foundVersion; UI resolves message via dict; review caught hardcoded FR in domain layer). - learnings.md +LRN-017 (i18n dict parity test: Object.keys().sort() equality + non-empty value assertion — cheapest drift guard). - learnings.md +LRN-018 (useT hook pattern: selector subscribe + dict closure-per-render, no prop drilling, missing-key dev-warn + key-literal fallback). - learnings.md +LRN-019 (exhaustive-deps trap when closures over store values appear inside useMemo deps — inline or useCallback). - evals.md +EVAL-002 (B3 review caught critical FR leak in pdf/import.ts + attachment.ts that grep+analyzer both missed — i18n migrations must enumerate ALL string-emitting files including error paths). - journal.md session 3 entry under 2026-05-20. - TODO.md B3 subsection rewritten as DONE with checked checkboxes + cross-refs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
9916c42484
commit
31bd82de58
7 files changed
+111
-21
No files matched your search
@@ -123,3 +123,33 @@ Apply: any fan-out fetch / parse / transform over heterogeneous sources — conf
|
||||
|
||||
pdf-lib with embedded TTF fonts (Inter, Fraunces) subsets glyphs and stores text streams as glyph indices, not codepoints. A latin1 / utf-8 grep over the raw PDF bytes will not match user-visible strings ("Temporo" never appears literally in the dump). Standard PDF text show ops (`Tj`, `TJ`) carry the glyph IDs inside content streams that are typically Flate-encoded too.
|
||||
Testing implication: don't assert PDF text via byte grep — either re-extract the embedded JSON attachment (already plain text) or refactor the offending logic into an exported helper and unit-test that. Same pattern when smoke-testing PDF output in CI.
|
||||
|
||||
---
|
||||
|
||||
## LRN-017 | 2026-05-20 | i18n dict parity via Object.keys.sort equality
|
||||
|
||||
Cheapest drift guard between fr/en dicts: one test asserts `Object.keys(fr).sort()` deep-equals `Object.keys(en).sort()` + every value non-empty. Catches any forgotten translation at CI time without enumerating keys. Pairs with a flat `<area>.<key>` convention so adding a key in fr.ts forces matching update in en.ts at the next test run.
|
||||
Apply: any project with N parallel translation dicts (i18n, locale strings, error-code maps). Beats type-level enforcement (TS can't easily require Record<K, ...> shapes to match across two `as const` literals without ceremony).
|
||||
|
||||
---
|
||||
|
||||
## LRN-018 | 2026-05-20 | useT hook: selector subscribe + closure-per-render
|
||||
|
||||
```ts
|
||||
export function useT() {
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const dict = getDict(locale)
|
||||
return (key) => dict[key] ?? (warn(key), key)
|
||||
}
|
||||
```
|
||||
Selector subscribe re-renders consumer only on locale change. Dict resolved once per render, the returned closure does a single hash lookup per call. No prop drilling, no context provider, no React `useMemo` needed. Missing-key path warns in DEV (`import.meta.env?.DEV`) and falls back to the key literal so the UI never crashes on a typo.
|
||||
Apply: any Zustand-state-driven derived computation that needs to re-render N components without prop chains. Same pattern works for theme tokens, feature flags, current user.
|
||||
|
||||
---
|
||||
|
||||
## LRN-019 | 2026-05-20 | exhaustive-deps trap with closures over store values
|
||||
|
||||
Defining a helper like `const nameOf = (z) => locale === 'en' ? z.name_en : z.name_fr` inside a component and using it inside `useMemo([deps])` triggers `react-hooks/exhaustive-deps`: nameOf is a fresh function each render, listing it in deps invalidates the memo every render; omitting it makes the linter complain. Two fixes:
|
||||
1. Inline the locale-conditional inside the memo body (no closure).
|
||||
2. Wrap the helper in `useCallback([locale])` so it's referentially stable.
|
||||
Inline is simpler when the helper is one expression. Apply: any closure that bridges a memoized computation to an outer hook value (store selector, prop, context). Same trap with `useEffect` deps.
|
||||
Reference in new issue
Block a user