react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

mergeProps doesn't work for Server Components

Open boar-is opened this issue 8 months ago โ€ข 1 comments

Provide a general summary of the issue here

Using mergeProps in server components gives the following error:

Error: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it.

The only solution is to mark component with 'use-client' directive.

๐Ÿค” Expected Behavior?

Being able to use the function in server components.

๐Ÿ˜ฏ Current Behavior

Can't be used without client components boundary.

๐Ÿ’ Possible Solution

Function's implementation is pretty straightforward. It uses mergeIds from useId.ts. This function does not use any "client" features, but the file itself imports them. The solution I see is to extract idsUpdaterMap and mergeIds to another file so it doesn't import any hooks/contexts.

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://stackblitz.com/edit/stackblitz-starters-zsr6u8?file=app%2Fpage.tsx

Here I just import mergeProps to a server component. This is enough to raise the error.

Version

@react-aria/utils 3.24.1

What browsers are you seeing the problem on?

Other

If other, please specify.

No response

What operating system are you using?

Windows

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

boar-is avatar Jun 21 '24 20:06 boar-is