fix(ui): add 'use client' to chart components using React hooks#144
Open
bntvllnt wants to merge 4 commits intofeat/storybookfrom
Open
fix(ui): add 'use client' to chart components using React hooks#144bntvllnt wants to merge 4 commits intofeat/storybookfrom
bntvllnt wants to merge 4 commits intofeat/storybookfrom
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
Author
|
Status: ready for final human review. Blockers: none. What changed in this pass:
Validation summary:
Claude review result:
Codex review result:
Action for bntvllnt:
|
…ct-hooks-missing-use-client-'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
"use client"topackages/ui/src/components/chart/area-chart.tsxandline-chart.tsx. Both components calluseMemo/useState/useId, so without the directive they crash Next.js App Router consumers withTypeError: c.useState is not a functionwhen imported into a Server Component tree (see Components using React hooks missing 'use client' directive — crashes Next.js RSC consumers #137).packages/ui/scripts/check-use-client.tsscans every non-story/test.tsxundersrc/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..github/workflows/ci.ymlas a new Quality Gates step (Check "use client" directives) and exposes it viapnpm -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/storybookTest plan
npx tsx scripts/check-use-client.tsfrompackages/ui— passes (OK: all 106 component file(s) with React hooks declare "use client".)area-chart.tsxandline-chart.tsxboth start with"use client";and no other component undersrc/components/uses a React hook without it.Check "use client" directivesstep.AreaChart/LineChartfrom@vllnt/uiinto a Next.js 16 App Router Server Component page and confirm it renders without theuseState is not a functioncrash.Fixes #137