Closed jgoux closed 4 years ago
🤔 Hmmm interesting. I'll spin up a CodeSandbox using _app.js
and see if I can get a reproduction this weekend.
Same issue. @parkerziegler You need download it from CodeSandbox
, you will see.
If we upgrades urql@1.7.0
and next-urql@0.2.2
to latest then we will be another problem
Cannot read property 'replace' of undefined
TypeError: Cannot read property 'replace' of undefined
at /**/node_modules/isomorphic-unfetch/index.js:3:36
@nghiepit yep I can repro the above. I've hit this same error before, but I can't quite remember what the fix was. Doing some more digging now. Thanks all for being patient, I've had other things on my plate recently but I hope to be able to figure this out now with some dedicated time for it.
So some progress! After digging around in node_modules
, logging some things out, and examining the stack trace, it's clear that when using _app.js
the first call to executeFetch
here: https://github.com/FormidableLabs/urql/blob/99375ff1ce418dfd8d28347695ee29c5cbde6f5f/src/exchanges/fetch.ts#L105 is receiving an operation
with no url
in its context
:
operation {
key: 2072880159,
query: {
kind: 'Document',
definitions: [ [Object] ],
loc: { start: 0, end: 190 },
__key: 407398015 },
variables: { first: 20 },
operationName: 'query',
context: {
url: undefined, // Yikes, this is coming in as undefined.
fetchOptions: undefined,
fetch: undefined,
requestPolicy: 'cache-first',
pollInterval: undefined,
meta: {
cacheOutcome: 'miss'
}
}
}
I'm not positive why that it is. I'll do a little more digging and consult with some folks here, since this seems like pretty strange behavior.
this also happens to me with the nextjs example from the urql repo
Yeah, I'm thinking there may be some discrepancies between how Next handles getInitialProps
calls for pages and components, and how it handles it for _app.js
and _document.js
. _app.js
getInitialProps
apparently gets called before any other getInitialProps
, even those on _document.js
: https://spectrum.chat/next-js/general/app-js-getinitialprops-explained~539bdc35-a8b0-4dfa-972b-0dd9a0f1ac67 It could also be an issue with react-ssr-prepass
and latest React: https://github.com/FormidableLabs/react-ssr-prepass/issues/28
Should be released in v0.2.3. Let me know if you're still experiencing issues 😄 Cheers!
Hello,
the doc seems to indicate that it's possible to wrap the App (from _app.js) with withUrqlClient if we don't mind losing static optimization, which is my case.
I just tried and I get this error :
Everything works fine when I wrap my pages instead of _app! 👍