Skip to content

feat(core)!: API-design consistency pass — v7.0.0#205

Open
childrentime wants to merge 1 commit into
mainfrom
fix/api-design-cleanup
Open

feat(core)!: API-design consistency pass — v7.0.0#205
childrentime wants to merge 1 commit into
mainfrom
fix/api-design-cleanup

Conversation

@childrentime

Copy link
Copy Markdown
Owner

What & why

Audited all 112 hook signatures against The Little Manual of API Design (Blanchette / Trolltech, mirrored at /papers/api-design). This fixes the public-API defects it surfaced and adds an authoritative spec so new hooks don't drift.

Per semver this is a major (7.0.0) — the fixes are renames/reorders of published API. All changes are mechanical with no behavior change.

Breaking changes

Change Manual rule Migration
useWindowsFocususeWindowFocus (+ param defauleValuedefaultValue) §3.8 — a shipped typo is locked forever (the SHStripMneumonic story); §4.4 no typos import { useWindowFocus } from '@reactuses/core'
useCookie(key, options?, defaultValue?)useCookie(key, defaultValue?, options?) §4.2 / §2.3 — options was mid-positional, inconsistent with useLocalStorage/useSessionStorage; a string in the useLocalStorage shape was silently typed as CookieAttributes useCookie('t', 'guest', { path: '/' })
useScrollIntoView / useSticky: first param targetElementtarget §4.2 — matches the 20 other DOM-target hooks positional callers unaffected

Non-breaking

  • JSDoc typos fixed (show up in editor autocomplete): usePreferredDark, usePreferredLanguages, useRafFn, useCookie (defaule / immediatly / incase).

New: .claude/api-design.md

The public-signature contract — parameter order ((subject, …, options?)), naming (incl. the intentional default* SSR-fallback vs initial* mutable-seed distinction — deliberately not flattened, per §4.3 false consistency), return shape (tuple vs object), and SSR defaults. The manual's 12 guidelines are mapped to concrete repo rules, plus a grandfathered-deviations table for issues that need a deliberate decision rather than churn:

  • Value/State suffix drift (defaultState ×5, some initialState) — param-name only, non-breaking, converge incrementally
  • useElementSize[w, h] tuple vs useWindowSize{ width, height } object — return-shape change, needs a major-version call
  • useFavicon(href, baseUrl, rel) trailing bare positionals; useSticky required mid-positional config

Wired into CLAUDE.md, .claude/README.md, .claude/knowledge-base.md, and the new-hook skill so the convention is enforced going forward.

Also updated

  • website-astro hook docs (en / zh-Hans / zh-Hant) + the browser-tab-ux blog posts → new names / argument order.
  • packages/core bumped to 7.0.0; changelog entry with migration notes.

Verification

  • jest59 suites / 305 tests pass (incl. useCookie with reordered args)
  • eslint clean on changed files
  • Historical changelog entries and the legacy website-docusaurus site left untouched (history / archived).

🤖 Generated with Claude Code

Audited all 112 hook signatures against The Little Manual of API Design
(/papers/api-design). Fixes the public-API defects it surfaced and adds an
authoritative spec so new hooks don't drift.

Breaking (renames/reorders only — no behavior change):

- useWindowsFocus -> useWindowFocus: the published export carried a stray
  "s" (concept is "window focus"). Its `defauleValue` param -> `defaultValue`.
  A shipped typo is locked forever (manual §3.8, the SHStripMneumonic story).
- useCookie(key, options?, defaultValue?) -> useCookie(key, defaultValue?, options?):
  options was in the middle, inconsistent with useLocalStorage/useSessionStorage
  and a "hard to misuse" trap — a string passed in the useLocalStorage shape was
  silently typed as CookieAttributes (manual §4.2 / §2.3).
- useScrollIntoView / useSticky: first param `targetElement` -> `target`, matching
  the 20 other DOM-target hooks (manual §4.2). Positional callers unaffected.

Non-breaking:

- Fixed JSDoc typos in editor autocomplete: usePreferredDark, usePreferredLanguages,
  useRafFn, useCookie ("defaule"/"immediatly"/"incase").

Docs:

- New .claude/api-design.md — the public-signature contract (parameter order,
  naming incl. default* vs initial*, return shape, SSR defaults), with the manual's
  guidelines mapped to concrete repo rules and a list of grandfathered deviations
  (Value/State suffix drift, useElementSize tuple vs useWindowSize object,
  useFavicon trailing positionals, useSticky mid-positional config). Wired into
  CLAUDE.md, .claude/README.md, knowledge-base.md, and the new-hook skill.
- Updated website-astro hook docs (en/zh-Hans/zh-Hant) and the browser-tab-ux blog
  posts to the new names/argument order.

Tests: 59 suites / 305 tests green; eslint clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant