Skip to content

fix(ui): add 'use client' to chart components using React hooks#144

Open
bntvllnt wants to merge 4 commits intofeat/storybookfrom
fix/issue-137-components-using-react-hooks-missing-use-client-
Open

fix(ui): add 'use client' to chart components using React hooks#144
bntvllnt wants to merge 4 commits intofeat/storybookfrom
fix/issue-137-components-using-react-hooks-missing-use-client-

Conversation

@bntvllnt
Copy link
Copy Markdown
Collaborator

Summary

  • Adds "use client" to packages/ui/src/components/chart/area-chart.tsx and line-chart.tsx. Both components call useMemo/useState/useId, so without the directive they crash Next.js App Router consumers with TypeError: c.useState is not a function when imported into a Server Component tree (see Components using React hooks missing 'use client' directive — crashes Next.js RSC consumers #137).
  • Adds a regression guard: packages/ui/scripts/check-use-client.ts scans every non-story/test .tsx under src/components/ and fails CI if any file referencing a React hook (useState, useEffect, useRef, useLayoutEffect, useCallback, useMemo, useReducer, useContext, useImperativeHandle, useId, useTransition, useDeferredValue, useSyncExternalStore, useInsertionEffect) is missing a leading "use client" directive.
  • Wires the audit into .github/workflows/ci.yml as a new Quality Gates step (Check "use client" directives) and exposes it via pnpm -F @vllnt/ui check:use-client.

A repo-wide sweep confirmed those two chart files were the only remaining offenders; other components listed in the issue either don't exist in this repo or already carry the directive.

Base: feat/storybook

Test plan

  • npx tsx scripts/check-use-client.ts from packages/ui — passes (OK: all 106 component file(s) with React hooks declare "use client".)
  • Manual verification: confirm area-chart.tsx and line-chart.tsx both start with "use client"; and no other component under src/components/ uses a React hook without it.
  • CI Quality Gates job runs the new Check "use client" directives step.
  • Downstream smoke: import AreaChart/LineChart from @vllnt/ui into a Next.js 16 App Router Server Component page and confirm it renders without the useState is not a function crash.

Fixes #137

AreaChart and LineChart call useMemo/useState/useId but lacked the
'use client' directive, causing Next.js App Router consumers to crash
with "useState is not a function" when the components are imported into
a Server Component tree.

Also add a CI audit script (scripts/check-use-client.ts) wired into the
Quality Gates workflow that fails if any component source uses React
hooks without declaring 'use client' on its first line, so this class
of regression is caught before publishing.

Fixes #137
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

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

Project Deployment Actions Updated (UTC)
storybook Ready Ready Preview, Comment Apr 26, 2026 2:39pm
ui.vllnt.ai Ready Ready Preview, Comment Apr 26, 2026 2:39pm

Request Review

@bntvllnt
Copy link
Copy Markdown
Collaborator Author

bntvllnt commented Apr 24, 2026

Status: ready for final human review.

Blockers: none.

What changed in this pass:

  • pushed 5fe2a46 to merge the latest feat/storybook into this branch and clear the remaining PR conflict
  • resolved the add/add conflict in packages/ui/src/components/client-directives.test.ts by keeping the branch helper/unit coverage and the base integration scan together
  • confirmed PR fix(ui): add 'use client' to chart components using React hooks #144 is back to a clean merge state against feat/storybook

Validation summary:

  • pnpm -F @vllnt/ui exec eslint scripts/check-use-client.ts src/components/client-directives.test.ts src/components/chart/area-chart.tsx src/components/chart/line-chart.tsx --max-warnings 0 --no-warn-ignored
  • pnpm -F @vllnt/ui exec vitest run src/components/client-directives.test.ts (34 passed)
  • pnpm -F @vllnt/ui exec tsx scripts/check-use-client.ts
  • pnpm -F @vllnt/ui exec tsc --noEmit --project tsconfig.build.json
  • pnpm -F @vllnt/ui build
  • gh pr checks 144 (current Vercel preview checks passing on head 5fe2a46)

Claude review result:

  • BLOCKING: none on the live narrowed diff vs feat/storybook
  • WARN: low-priority follow-up only — CI calls npx tsx instead of the package script, the integration test skip list does not mirror the script's .spec.tsx exclusion, and hasUseClientDirective() still has an unusual mid-line */ parser edge case

Codex review result:

  • attempted on the narrowed live diff, but Codex returned an account usage-limit error before it produced a review artifact

Action for bntvllnt:

@bntvllnt bntvllnt marked this pull request as ready for review April 24, 2026 21:55
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