Issue with SSR and requestInterceptors
See original GitHub issueThanks for this amazing library. It looks great and almost works perfectly! I’m trying to set this up in a SSR NextJS project. I’ve used these instructions from the documentation and SSR works great.
My next step was to add a requestInterceptor so that I don’t have to type the base API domain over and over again. For this I used your example host interceptor. As follows:
const requestHostInterceptor = host => client => async action => {
return {
...action,
endpoint: `${host}${action.endpoint}`,
}
}
export const client = createClient({
cacheProvider: cache,
requestInterceptors: [requestHostInterceptor('http://local.api.dev')],
})
But SSR stops working as soon as I add the requestInterceptors
property to createClient
. The endpoint gets called twice (first backend, then frontend again because it finds there is no cache). So the client is making the call correctly from the backend to the api, but somehow the payload remains undefined
while rendering on the server.
I’ve looked through the code, but can’t find any pointers. Do you have any ideas?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Here is the codesandbox link, not really familiar with codesandbox, so hope it’s correct: https://codesandbox.io/s/react-fetching-library-ssr-nextjs-u5827
Excellent! Works like a charm. Thanks so much for the quick response.