Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nextjs): Introduce build-time error for server-only helpers on client-side #3758

Merged
merged 4 commits into from
Jul 18, 2024

Conversation

LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Jul 18, 2024

Description

Resolves #3660

Uses the server-only package to throw a build-time error if Clerk server-side helpers get accidentally imported on the client side.

CleanShot 2024-07-18 at 09 57 12@2x

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@LauraBeatris LauraBeatris self-assigned this Jul 18, 2024
Copy link

changeset-bot bot commented Jul 18, 2024

🦋 Changeset detected

Latest commit: e8048e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/nextjs Patch

Not sure what this means? Click here to learn what changesets are.

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

@LauraBeatris LauraBeatris changed the title chore(nextjs): Introduce build-time error for server-only helpers on client-side context chore(nextjs): Introduce build-time error for server-only helpers on client-side Jul 18, 2024
@LauraBeatris LauraBeatris changed the title chore(nextjs): Introduce build-time error for server-only helpers on client-side chore(nextjs): Introduce build-time error for server-only helpers on client-side Jul 18, 2024
@LauraBeatris LauraBeatris marked this pull request as ready for review July 18, 2024 13:59
@LauraBeatris LauraBeatris requested review from BRKalow and a team July 18, 2024 13:59
@@ -1,3 +1,5 @@
jest.mock('server-only', () => null);
Copy link
Member Author

Choose a reason for hiding this comment

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

It's tricky to run server-only on Jest due to its multiple environments. I went ahead and decided to mock it instead:

reactjs/rfcs#227 (comment)

@@ -1,3 +1,5 @@
import 'server-only';
Copy link
Member Author

@LauraBeatris LauraBeatris Jul 18, 2024

Choose a reason for hiding this comment

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

I've imported it separately on auth and currentUser only instead of importing it once on server index.

My concern is that the error would be thrown even when importing type definitions, but I'd like to minimize the surface here.

@LauraBeatris LauraBeatris merged commit 18bcfbc into main Jul 18, 2024
16 checks passed
@LauraBeatris LauraBeatris deleted the server-only-build-time-error branch July 18, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@clerk/nextjs@5.2.0 cause a build warning in NextJS middleware
3 participants