Skip to content
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

Update usage-next-13.mdx: BlitzProvider as client component #847

Closed
wants to merge 1 commit into from

Conversation

tordans
Copy link
Contributor

@tordans tordans commented Oct 13, 2023

Theres is also the request for help at https://discord.com/channels/802917734999523368/1161576668863922176.

See also blitz-js/blitz#4232.

Change

My understanding is, that BlitzProvider is a client component and the way I understand the app directory means that everything below in the include-tree needs to be a client component as well.

Testcase

  1. checkout https://github.com/FixMyBerlin/blitz-test/commits/blitzprovider-test which is the error case without the use client in the layout file that holds the blitzprovider
  2. See error

Error

Unhandled Runtime Error
Error: Unsupported Server Component type: undefined

image

@vercel
Copy link

vercel bot commented Oct 13, 2023

@tordans is attempting to deploy a commit to the Blitz Team on Vercel.

A member of the Team first needs to authorize it.

@siddhsuresh
Copy link
Member

siddhsuresh commented Oct 13, 2023

@tordans I do not understand this, BlitzProvider is a client component and takes the rest of the application as props. We are following this pattern https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#supported-pattern-passing-server-components-to-client-components-as-props

We can definitely use server components with blitz. You do not need to make all pages "use client" client components.

I might have misunderstood your intention and I am looking at the issues referenced now.

@@ -58,6 +57,8 @@ export const {withBlitz, BlitzProvider} = setupBlitzClient({

```tsx
// layout.ts
'use client'
Copy link
Member

@siddhsuresh siddhsuresh Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to learn how :-). The "Testcase" I described above shows the issue. Add/remove the "use client" and it works or doen't…

@@ -24,14 +24,13 @@ the following methods and hooks have been implemented to work in the new `app` d

#### Required changes {#required-changes}

Add the new `use client` directive to the following files:
Add the new `use client` directive to **all** files in the include-tree below [`BlitzProvider`](https://blitzjs.com/docs/usage-next-13#blitz-provider), which is a client component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is, that https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#unsupported-pattern-importing-server-components-into-client-components

You cannot import a Server Component into a Client Component

Results is a bad error message

Error: Unsupported Server Component type: undefined

One thing I did was to remove all barrel files from our project in order to work around this issue, as suggested in vercel/next.js#41940

(But in the end we added 'use client' to all files (for now), just to get to a working version.)

My current understanding is: Since I cannot import server components into client components and I cannot audit every include, for the slot-workaround you mentioned, I have to add use client to all files that are imported in other files.

@tordans
Copy link
Contributor Author

tordans commented Oct 25, 2023

The changes I propose here are wrong, I will close the PR.

@tordans tordans closed this Oct 25, 2023
@tordans tordans deleted the patch-7 branch October 25, 2023 14:50
@blitzjs-bot blitzjs-bot moved this from In Review to Done in HQ Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
HQ
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants