Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Next.js 13: SWRConfig should mark components as "use client" #2253

Closed
itta611 opened this issue Nov 28, 2022 · 1 comment
Closed

Next.js 13: SWRConfig should mark components as "use client" #2253

itta611 opened this issue Nov 28, 2022 · 1 comment

Comments

@itta611
Copy link

itta611 commented Nov 28, 2022

Bug report

SWRConfig is used for top class components (e.g. layout), but the component SWRConfig is not defined as the Client Components.
Therefore, developer have to write "use client", which makes all components in the layout as Client Components.

Description / Observed Behavior

Server Error
TypeError: react.createContext is not a function

Expected Behavior

Therefore, the developer must write "use client", which makes all components in the layout client components.

Additional Context

swr: 1.3.0
next: 13.0.2

@SukkaW
Copy link

SukkaW commented Dec 10, 2022

The current workaround would be manually wrapping <SWRConfig /> in your client components:

// my-provider.client.tsx
'use client';
export const MyProvider = ({ children }: React.PropWithChildren<unknown>) => {
  return <SWRConfig>{children}</SWRConfig>
};

// layout.tsx
export default function Layout({ children }: React.PropWithChildren<unknown>) {
  return <MyProvider>{children}</MyProvider>
}

And IMHO <SWRConfig /> should also include import 'client-only'.

@vercel vercel locked and limited conversation to collaborators Dec 15, 2022
@koba04 koba04 converted this issue into discussion #2292 Dec 15, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants