-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
getBlitzContext() can only be used in React Server Components in Nextjs 13 or higher #4242
Comments
Thanks for the issue, this has been fixed in the latest release -import { gSSP, invoke } from "src/blitz-server"
+import {gSSP} from "src/blitz-server"
+import {invoke} from "@blitzjs/rpc" I am closing the issue since this issue has already been fixed. If it is still present in the latest version, please inform and update the issue. Thanks! |
I get this error in new version when i use Internal error: Error: getBlitzContext() can only be used in React Server Components in Nextjs 13 or higher |
@akboolz Had the same problem after updating to .35 but using the fix to import invoke like |
Well its not the same I think. Because query In blitz docs: So Query function:
Error if importing
My sample code in
The strange thing is that it works on first load but after changing code / page refresh / link click, this error can show up randomly. |
@akboolz that would be a question for @siddhsuresh. Or maybe a new ticket to give the |
@akboolz to be more clear, all usages of Hope this solves your issue. |
@siddhsuresh we upgraded our app (app directory) from beta .34 to beta .35 and we now have the same issue with the missing session when Please reopen this issue. Update: There is a test case app for this error in #4243 (comment) |
@siddhsuresh thanks for looking into this and reopening the issue!
First test case:I am getting
For the page http://127.0.0.1:5173/regionen which loads this file https://github.com/FixMyBerlin/atlas-app/blob/develop/src/app/regionen/(index)/page.tsx (a RSC) which imports two RSC:
Second test case:I updated the test app for #4243 (comment) and the error cases described in that commend are still same. For this ticket the last error is relevant at http://localhost:3000/projects-session-error/foo
This is a server component using invoke from Third test case:Update: This test case was wrong. Following the docs https://blitzjs.com/docs/usage-next-13#app-directory for how to get ctx and user does work. |
@tordans thanks for the very detailed explanation. Importing Now regarding the If this is not the case, will try replicating the issue by cloning your repo, since this looks to be severe |
@siddhsuresh I am getting super confused by this error. It is there on one day and gone the next 😞. I am removing The error I see, when I see it (in both the test app and our real app), is …
I will try again next week… I can say that the behavior is different between dev and production env. In case someone want to add data points, here is my test setup:
(And a similar test for https://github.com/FixMyBerlin/atlas-app/blob/develop/src/app/regionen/(index)/_components/RegionListNonpublic.tsx) |
What is the problem?
when i use next13 i found problem in "invoke function"
i get error "getBlitzContext() can only be used in React Server Components in Nextjs 13 or higher"
in Page.ts
`
import { gSSP, invoke } from "src/blitz-server"
export const getServerSideProps = gSSP(async ({ ctx }) => {
const data = await invoke(..., null)
return { props: { data } }
})
`
in blitz-server.ts
export const { gSSP, gSP, api, invoke } = setupBlitzServer({ plugins: [ AuthServerPlugin({ ...authConfig, storage: PrismaStorage(db), isAuthorized: simpleRolesIsAuthorized, }), RpcServerPlugin({}) ], logger: BlitzLogger({}) });
how i can fix?
The text was updated successfully, but these errors were encountered: