Closed hrougier closed 3 months ago
This is because CharacterFragment
is considered part of the client-module, hence when we try to merge the definitions
(fragments) of said client export in the main operation we are dis-allowed. I don't really understand this limitation but it seems like one that Next chose conciously, not much we can do about that though.
I've been doing some investigating here, since I haven't really looked into this much yet. As it stands, Next.js doesn't seem to “split” client-modules and expose side-effect-less values.
Like, you can even add export const test = 'test';
in your client-modules, import that in your server file, and that would be replaced by a client reference.
So, you can't seemingly colocate fragments with client-components, while using them from a server component. You'd basically instead have to keep all components that consume fragments to either be universal (i.e. unmarked) or split your fragment out into a colocated file.
Just to clarify, yes, this does look very annoying. I hope there'll eventually be a solution to mark individual client-module exports as side-effectless and reusable i.e. shared.
Closing due to inactivity and since — seemingly — at least, we can't do much about this. My hope is that the React/Next teams support shared exports from client-component modules in the future to support colocated exports.
Describe the bug
Using the following stack:
With fragment masking over react client & server components:
page.tsx
(Server Component)Character.tsx
(client component)The following error is thrown:
Is there some way to make this pattern work?
Reproduction
https://github.com/hrougier/gql.tada
gql.tada version
gql.tada v1.5.1
Validations