Open lksnmnn opened 3 years ago
Thanks!
For whoever wants to look into this, this function (https://github.com/blitz-js/blitz/blob/canary/packages/core/src/utils/react-query-utils.ts#L23-L30) should be defining the query retry behavior. But it seems that maybe that function isn't even being used? Idk, but that's the place to start.
~Yes, I added a console log and this retry callback is actually not being called in this case.~ This seems to be an issue in react-query
then? I've just skimmed through some issues and it seems that there are more subtle issues with react-query
that explain some of the bugs we are currently seeing in blitz.
Edit: when I set suspense
to false
, it works as expected and runs the shouldRetry
callback
Edit 2: I had to re-run yarn dev and now I can see that the retry function is being used and returns false as expected
Hm. The more I look at the code the weirder it gets. I dont think that it actually does retry the fetch request (network tab shows only a single request) but it runs through the useQuery -> useBaseQuery() code multiple times during render and then just throws the error multiple times, everything else seems to work correctly ?!
If suspense
is false
, then it won't even render the error fallback, if I set useErrorBoundary: true
it behaves just like as suspense
is true
.
If suspense is false, then it won't even render the error fallback, if I set useErrorBoundary: true it behaves just like as suspense is true.
This is correct behavior
Hm. The more I look at the code the weirder it gets. I don't think that it actually does retry the fetch request (network tab shows only a single request) but it runs through the useQuery -> useBaseQuery() code multiple times during render and then just throws the error multiple times, everything else seems to work correctly ?!
This does seem suspicious 🤔 . If it's a RQ issue, then next step is to make a failing RQ test and open an issue over there with it
I have just run into the same/a similar issue. I have a query exactly like this example https://blitzjs.com/docs/use-query but the ErrorBoundary is never triggered and infinitely retries the query.
It's throwing an error, but it's just never caught by ErrorBoundary:
[
{
code: 'EPC-1400',
description: 'Invalid or expired Partner Access Token',
type: 'system',
resourceId: 'ORIGIN'
}
]
14:16:29.323 ERROR fetchLoan()
EpcError
details:
{
name: 'EpcError',
code: 'EPC-1400'
}
error stack:
• blitzjs-core-server.cjs.dev.js:356 <anonymous>
node_modules/@blitzjs/core/server/dist/blitzjs-core-server.cjs.dev.js:356:20
• blitzjs-core-server.cjs.dev.js:1606 <anonymous>
node_modules/@blitzjs/core/server/dist/blitzjs-core-server.cjs.dev.js:1606:22
• blitzjs-core-server.cjs.dev.js:81 handleRequestWithMiddleware
node_modules/@blitzjs/core/server/dist/blitzjs-core-server.cjs.dev.js:81:5
• api-utils.ts:84 apiResolver
node_modules/next/next-server/server/api-utils.ts:84:5
• next-server.ts:1160 handleApiRequest
node_modules/next/next-server/server/next-server.ts:1160:5
• next-server.ts:1013 fn
node_modules/next/next-server/server/next-server.ts:1013:27
• router.ts:346 execute
node_modules/next/next-server/server/router.ts:346:24
• next-server.ts:1258 run
node_modules/next/next-server/server/next-server.ts:1258:23
• next-server.ts:568 handleRequest
node_modules/next/next-server/server/next-server.ts:568:14
@cj can you try this and let me know if it works or not? Add this code to _app.tsx
import {EpcError} from 'where-ever-this-comes-from'
import SuperJson from "superjson"
SuperJson.registerClass(EpcError, {
identifier: "EpcError",
allowProps: ["name", "message", "code", "statusCode", "meta"],
})
@flybayer let me give that a try. Does SuperJson need to be in _app? I currently have https://gist.github.com/cj/073baeb3eb07257e7f27a6df0c90419b
Ah yeah, because SuperJson.registerClass
must be executed on both client and server. If it's in the resolver, it only executes server side but not client side
What is the problem?
A ChildComponent executes a query, which throws a 404 NotFoundError. The ChildComponent lives inside an ErrorBoundary with its own fallback. The query is being retried at least 3 times before the boundary finally renders the fallback and calls its
onError
callback.We chatted about this in a discordia help channel: https://discord.com/channels/802917734999523368/814628031322128394/844583897223135303
Expectation: No retries on 404.
Paste all your error logs here:
Paste all relevant code snippets here:
index.tsx
Query:
What are detailed steps to reproduce this?
Here is repo (
blitz new
) with the above query and components added toindex.tsx
, which reproduces the issue. Just install and runblitz dev
https://github.com/lksnmnn/blitz-404-error-boundary-issue
Run
blitz -v
and paste the output here:This does also occure with node 14 and npm 7.
Please include below any other applicable logs and screenshots that show your problem:
No response