fix(avatar): mark Pharos as client-only via 'use client' banner#79
Merged
Conversation
`Avatar` (D14) calls `createContext(...)` three times at module top level. Without a `"use client"` marker, Next.js evaluates the module during its RSC build-time analysis pass and crashes with `TypeError: (0 , c.createContext) is not a function` while collecting page data — observed during the first Alexandria adoption attempt of pharos-react `0.11.0`. Two coordinated changes: - `src/components/Avatar.tsx`: add `'use client';` at the top so the intent is visible in source. (Vite / esbuild strip per-file directives during bundling, so this alone does not reach the published artifact.) - `vite.config.ts`: emit `'use client';` as the bundle banner via `rollupOptions.output.banner`. This is what actually lands at the top of `dist/index.js` and stops Next.js from following the import into RSC analysis. The whole library shipping client-only matches what every React DS does (MUI / Chakra / Radix / shadcn). Card / Separator lose server-render-ability as a side effect — acceptable; nothing in the docs ever promised them as server-safe. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Tip All tests passed and all changes approved!🟢 UI Tests: 67 tests unchanged |
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
Avatar (D14) calls `createContext(...)` three times at module top level. Without a `"use client"` marker on the published bundle, Next.js evaluates the Pharos module during its RSC build-time analysis pass and crashes with:
```
TypeError: (0 , c.createContext) is not a function
at module evaluation
at instantiateModule (chunks/ssr/[turbopack]_runtime.js)
```
Observed in the first Alexandria adoption attempt of pharos-react 0.11.0 — page-data collection for `/[locale]/legal-and-privacy` (any route whose layout transitively imports an Avatar) fails the build.
Fix
Two coordinated changes:
Trade-off
The whole library ships client-only, not just Avatar. Card / Separator (which have no hooks) lose server-render-ability as a side effect. Acceptable because:
Quality
Test plan
🤖 Generated with Claude Code