Skip to content

Conversation

anshukushwaha07
Copy link

This PR fixes an error when using the Carousel component in Next.js 13+/15 Server Components:

TypeError: createContext only works in Client Components. 
Add the "use client" directive at the top of the file to use it.

The error occurs because Carousel uses client-only React APIs (useEffect, useState, createContext) but was not marked as a Client Component.

Fix: Added the "use client"; directive at the top of Carousel.tsx, ensuring Next.js correctly treats it as a Client Component.

Fixes #1094

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Verified build and tests pass locally (pnpm test).
  • Reproduced the error in a Next.js 15 sandbox before the change.
  • Confirmed that after this fix, Carousel can be used directly in both Client and Server Components wthout wrapper workarounds.

Checklist

  • My code follows the style guidelines of this project (pnpm run lint)
  • I have run the existing test suite locally (pnpm run test / pnpm run test:ci-with-server)
  • I have performed a self-review of my code
  • My changes generate no new warnings

Copy link

changeset-bot bot commented Sep 18, 2025

⚠️ No Changeset found

Latest commit: c675156

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 18, 2025

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

Project Deployment Preview Comments Updated (UTC)
nuka-carousel-website Ready Ready Preview Comment Sep 18, 2025 4:27am

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.

Carousel throws error inside server component
1 participant