Some time passed in the thread, so just to note my best practice here:
In client code, in particular on the threshold when I switch from server component to client component, I use
@@directive("'use client';")
In RSC code I don’t add this or any other directive.
Note that there is a use server;
but disturbing as it is, that is not the counterpart of use client
, but it has to do with Server Actions which is an entirely different concept (and which I don’t currently use).
I also have the following that I sometimes add to code that I only want to use from RSC:
@@directive("require('server-only');")
This is just a safeguard that makes sure that this code cannot accidentally “become” a client component.
It also has a client-only counterpart. This would error when a module designated for client only would accidentally be used from a RSC. But I have no use case where this would be useful.
That’s it… I’d prefer a more consistent pattern, but the inconsistency originates from nextjs, thus it cannot be resolved from Rescript.