emilkowalski / sonner

An opinionated toast component for React.
https://sonner.emilkowal.ski
MIT License
8.36k stars 262 forks source link

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

Open kentcdodds opened 7 months ago

kentcdodds commented 7 months ago

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: https://github.com/adobe/react-spectrum/pull/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 commented 4 days ago

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 commented 3 days ago

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

stevegreco commented 3 days ago

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?