Skip to content

feat: mark the components, hooks, factories and configureLottie as client modules - #138

Merged
Gamote merged 1 commit into
mainfrom
feat/use-client-directive
Aug 16, 2026
Merged

feat: mark the components, hooks, factories and configureLottie as client modules#138
Gamote merged 1 commit into
mainfrom
feat/use-client-directive

Conversation

@Gamote

@Gamote Gamote commented Aug 16, 2026

Copy link
Copy Markdown
Owner

What

Under React Server Components a module that only works in the browser says so with "use client", and a server component that imports it receives a client reference instead of evaluating it. Without the line, import { Lottie } from "lottie-react" in a server component made the Next build fail at page-data collection with TypeError: createContext is not a function (React's server build has no createContext, and our context modules evaluate it when the barrel is imported); the only route was the consumer's own "use client" file.

Now every component, every hook, the interaction factories and configureLottie start with the directive (16 modules). The barrel and the vocabulary maps stay unmarked: the barrel must be evaluated to re-export, and a server component may read LottieDirection.reverse. The rule is recorded in CLAUDE.md under "Modules and exports". Docs: the installation page says a server component can import the components directly, and that configureLottie, like the hooks, is called from client code; the configuring page says a server-side call fails at build time rather than configuring a copy the browser never sees.

Verified

  • tsdown keeps a top-of-file directive in both the ESM and the CJS output of exactly that file (probed and reverted before the change).
  • Packed build in a Next.js 16 Turbopack app: a server component importing Lottie directly builds, prerenders (element in the HTML), hydrates and plays; a server component calling configureLottie fails at build time with React's message ("Attempted to call configureLottie() from the server but configureLottie is on the client…"); client-component pages unchanged.
  • No directive warnings from Vite 8 (rolldown, our own website build) or esbuild (size-limit); Rollup-based bundlers (Vite 5 to 7) print their usual module-level-directive notice and continue, as for every RSC-ready library. Sizes unchanged.
  • pnpm check green: 488 tests, coverage 100 / 97.46 / 100 / 100, 36 pages rendered.

…ient modules

Under React Server Components a module that only works in the browser
says so with a directive, and a server component that imports it receives
a client reference instead of evaluating it. Without the line, importing
`Lottie` from a server component evaluated the context modules on the
server and the build failed on `createContext`; the only route was the
consumer's own client file.

Every component, every hook, the interaction factories and `configureLottie`
now start with `"use client"`, so a server component imports `<Lottie>`
directly, and a server-side call of `configureLottie` fails at build time
instead of configuring a copy the browser never sees. The barrel and the
vocabulary maps stay unmarked: the barrel must be evaluated to re-export,
and a server component may read `LottieDirection.reverse`. tsdown keeps
the directive at the top of each emitted file; the rule is recorded in
the build contract.
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.92%. Comparing base (4dcf4d7) to head (2be05d9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #138   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files          48       48           
  Lines        1253     1269   +16     
  Branches      365      365           
=======================================
+ Hits         1252     1268   +16     
  Misses          1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Gamote
Gamote merged commit 7667a74 into main Aug 16, 2026
6 checks passed
@Gamote
Gamote deleted the feat/use-client-directive branch August 16, 2026 20:46
@Gamote Gamote mentioned this pull request Aug 16, 2026
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