Skip to content

fix(frontend): add "use client" directive to Next.js 15 providers (#83)#88

Open
teddylee777 wants to merge 1 commit into
mainfrom
fix/issue-83-use-client-directives
Open

fix(frontend): add "use client" directive to Next.js 15 providers (#83)#88
teddylee777 wants to merge 1 commit into
mainfrom
fix/issue-83-use-client-directives

Conversation

@teddylee777
Copy link
Copy Markdown
Member

컨텍스트 블록

Key Value
Type fix
Scope frontend
Base main
Branch fix/issue-83-use-client-directives
Diff +8 / -0
Files 4 changed

요약

  • WHAT: frontend/src/providers/ 아래 4개 provider 파일 (Settings.tsx, AssistantConfig.tsx, Stream.tsx, Thread.tsx)의 맨 위에 "use client"; 지시문 추가
  • WHY: 이 컴포넌트들은 React hooks를 선언하고 browser API를 사용하며, 현재는 call site가 client component tree에 있어서 안전함. 하지만 향후 refactor로 이들이 Server Component에 hoisted될 경우 Next.js 15 RSC 경계 오류 발생 위험. 지시문이 이 취약점을 자체 문서화하는 defensive boundary로 변환
  • HOW: 각 파일 맨 위에 "use client"; 라인 추가 (한 줄 + 공백 라인)
  • IMPACT: Providers의 RSC 경계가 명확히 정의되어 향후 코드 변경 시 보호됨. 현재 consumer 동작에 영향 없음
  • RISK: Low — directive-only 추가, 로직 변경 없음, 테스트 완료

동기 / 배경

문제 정의

4개의 provider 컴포넌트가 React hooks와 browser API를 사용하고 있음. 현재 모든 call site가 client component 범위 내에 있어서 작동하지만, 향후 누군가 이 providers를 Server Component에서 호출하도록 refactor할 경우 Next.js 15에서 RSC 경계 오류가 발생함.

트리거

Issue #83에서 보고된 Next.js 15 RSC compliance 점검

이전 상태

4개 provider: 명시적 client 경계 없음, call site 의존성으로만 안전

변경 사항

File Action Description Design Rationale
frontend/src/providers/Settings.tsx Modify Line 1에 "use client"; 추가 Client-only hooks와 browser API 사용 명시
frontend/src/providers/AssistantConfig.tsx Modify Line 1에 "use client"; 추가 Client-only hooks 사용 명시
frontend/src/providers/Stream.tsx Modify Line 1에 "use client"; 추가 Client-only hooks 사용 명시
frontend/src/providers/Thread.tsx Modify Line 1에 "use client"; 추가 Client-only hooks 사용 명시

테스트 계획

# Type Command Expected Result Status
1 Manual head -1 frontend/src/providers/{Settings,AssistantConfig,Stream,Thread}.tsx 모든 파일이 "use client";로 시작 pass
2 Lint cd frontend && pnpm lint ESLint 오류 없음 pass
3 Type cd frontend && pnpm exec tsc --noEmit TypeScript 타입 오류 없음, exit 0 pass
4 Build cd frontend && pnpm build 모든 27개 route 성공적으로 컴파일 pass
5 Manual git diff --stat 정확히 4개 파일 변경, +8/-0 pass

관련 이슈

Closes #83

체크리스트

  • Branch name이 naming convention을 따름 (type/description)
  • Commit message가 conventional commit 템플릿을 따름
  • Type check가 통과함
  • Linter가 통과함
  • Secret이 commit되지 않음
  • 필요한 경우 documentation이 업데이트됨
  • 무관한 변경이 bundled되지 않음
  • Impact analysis 완료 (upstream/downstream 의존성 확인)

## What Changed
- Added `"use client";` directive at line 1 of 4 provider files under `frontend/src/providers/`:
  - `Settings.tsx`
  - `AssistantConfig.tsx`
  - `Stream.tsx`
  - `Thread.tsx`
- Each file receives the directive followed by a blank-line separator; all existing imports, hooks, JSX, and logic are untouched.

## Root Cause
The 4 provider components declare React hooks (`useState`, `useEffect`, `useCallback`, `useMemo`, `useRef`) at module scope and in `Settings.tsx` also touch client-only browser APIs (`document.documentElement`, `window.matchMedia`, `localStorage`). They are currently safe only because every call site lives inside a client component tree (`MainLayoutClient.tsx`, `ChatContent.tsx` both declare `"use client"`). Any future refactor that hoists one of these providers into a Server Component would fail at build time with a Next.js 15 RSC boundary error. The directive converts this latent fragility into a defensive, self-documenting boundary.

## Test Plan
- [x] `head -1 frontend/src/providers/{Settings,AssistantConfig,Stream,Thread}.tsx` → `"use client";`
- [x] `cd frontend && pnpm lint` → ✔ No ESLint warnings or errors
- [x] `cd frontend && pnpm exec tsc --noEmit` → exit 0
- [x] `cd frontend && pnpm build` → all 27 routes compile successfully
- [x] `git diff --stat` shows exactly 4 files changed, +8/-0

## References
Closes #83
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds explicit Next.js Client Component boundaries to provider modules to prevent future RSC boundary errors (Issue #83) if these hook/browser-API-using providers are ever imported from a Server Component.

Changes:

  • Add "use client"; directive to four provider modules under frontend/src/providers/.
  • Make the client-only intent of these providers explicit/defensive for Next.js 15 RSC compliance.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
frontend/src/providers/Settings.tsx Adds "use client"; at the top to declare client boundary for hook + browser API usage.
frontend/src/providers/AssistantConfig.tsx Adds "use client"; to ensure hook-based provider is always treated as a Client Component.
frontend/src/providers/Stream.tsx Adds "use client"; to enforce client boundary for stream/hooks-based provider.
frontend/src/providers/Thread.tsx Adds "use client"; to enforce client boundary for hook-based thread provider.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🟡[P2] fix(frontend): providers/Settings.tsx missing 'use client' directive despite using hooks + window/document

2 participants