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

Remove "use client" in favor of client-only #331

Closed
kentcdodds opened this issue Feb 9, 2024 · 4 comments
Closed

Remove "use client" in favor of client-only #331

kentcdodds opened this issue Feb 9, 2024 · 4 comments

Comments

@kentcdodds
Copy link

Describe the feature / bug 📝:

Right now sonner publishes "use client" in it's source. This should be an application-level concern rather than a library one. For more on this: adobe/react-spectrum#5826

As another motivation, using sonner with vite currently gives this error:

../../node_modules/sonner/dist/index.mjs (1:0) Module level directives cause errors when bundled, "use client" in "../../node_modules/sonner/dist/index.mjs" was ignored.

I think following the pattern taken by react-aria (simply using the client-only module by Sebastian) is the right approach here:

image

The resulting error message is better and it's less limiting.

@stevegreco
Copy link

I know this seems pretty old, but what is the thinking behind import client-only being a better approach compared too use client from a library perspective. Is the expectation that everyone just creates a wrapper around the component and add use-client?

@kentcdodds
Copy link
Author

The thinking is that the error message is more useful if someone accidentally imports it in the wrong environment.

@stevegreco
Copy link

I see. I guess my initial impression was that as someone using the library, it was less convenient than just having 'use client' embedded in the component itself.

It could be ignorance on my part, but I'm guessing that even with 'use client' in the component, you could still run into issues?

@emilkowalski
Copy link
Owner

Isn't this worse DX? <Toaster /> can now be imported into server components. Removing the use client directive will make that impossible.

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

No branches or pull requests

3 participants