-
Notifications
You must be signed in to change notification settings - Fork 36
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
Suspense Query Returns Data but Triggers Forbidden Error in Next.js 14 #367
Comments
Hi @naimulemon! 👋 Are you doing any additional steps to ensure that the SSR of your Client Components has access to the cookie? |
@phryneas What are the additional steps you talk about? This is my root layout
Here is my root layout
Here is my client .
|
Unfortunately, Next.js fails to provide easy access to cookies during the SSR of Client Components, so you have to retrieve your cookie in a RSC, pass it (potentially encrypted) to your See this example: #281 (comment) |
@phryneas My code is working on server component and client component when I use hook. I only give me issue when I use suspense query. What about prefetch and how can I use that? Is there any example with prefetch query? |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
Issue Description
When using Apollo Client's
SuspenseQuery
in a Next.js 14 project, the query successfully fetches and logs the data in the console, but it also throws a "Forbidden resource" error. The same query works perfectly with the standarduseQuery
, indicating that the issue arises specifically when using theSuspense
mode.This problem prevents proper error handling, as the error is emitted even when valid data is received. The error handling behavior appears inconsistent, and there’s no clear way to manage or silence the error when using the
useSuspenseQuery
.Suspense Query Code:
Despite data being logged successfully, the
SuspenseQuery
still triggers a runtime error:This error occurs when rendering the component within the
Suspense
boundary. When switching to the standarduseQuery
, no such error occurs, and data is returned without issue.Apollo Client Setup:
Steps to Reproduce
useGetUsersSuspenseQuery
to fetch data in a component.<Suspense>
and<ErrorBoundary>
in the page layout.credentials: "include"
is set in the Apollo Client configuration.403 Forbidden
error will also be thrown.Expected Behavior
The
SuspenseQuery
should correctly fetch and render the data without triggering a forbidden error, especially when the data is already successfully retrieved. Error handling should allow more control over dealing with the error (if any).Actual Behavior
The
SuspenseQuery
fetches data and logs it in the console, but simultaneously throws a runtime error (403 Forbidden
), causing the query to break in Suspense mode. There's no way to handle this error gracefully, even though the data is valid.Environment
@apollo/client
3.xhttp://localhost:8080/graphql
Additional Notes
Suspense
mode of Apollo queries, as the same query works flawlessly withuseQuery
.Link to Reproduction
https://github.com/naimulemon/Zuricart-official
Reproduction Steps
Steps to Reproduce
useGetUsersSuspenseQuery
to fetch data in a component.<Suspense>
and<ErrorBoundary>
in the page layout.credentials: "include"
is set in the Apollo Client configuration.403 Forbidden
error will also be thrown.@apollo/client
version3.10.6
The text was updated successfully, but these errors were encountered: