diff --git a/packages/pwa-kit-react-sdk/src/ssr/server/react-rendering.test.js b/packages/pwa-kit-react-sdk/src/ssr/server/react-rendering.test.js index c88ecb5639..befc3e4903 100644 --- a/packages/pwa-kit-react-sdk/src/ssr/server/react-rendering.test.js +++ b/packages/pwa-kit-react-sdk/src/ssr/server/react-rendering.test.js @@ -264,8 +264,8 @@ jest.mock('../universal/routes', () => { } const GetServerContext = () => { - const {res, isServerSide} = useServerContext() - if (isServerSide) { + const {res} = useServerContext() + if (res) { console.log('--- isServerSide') res.status(404) } @@ -716,9 +716,8 @@ describe('The Node SSR Environment', () => { assertions: (res) => { expect(res.statusCode).toBe(404) - // Expect the console.log to be called only once, even though the component - // is going to be rendered twice on the server (on prepass and then 2nd pass) - expect(console.log).toHaveBeenCalledTimes(1) + // Because of the prepass step we'll expect that this method is called twice. + expect(console.log).toHaveBeenCalledTimes(2) } } ] diff --git a/packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js b/packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js index f6c3db36c2..91951b2057 100644 --- a/packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js +++ b/packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js @@ -52,11 +52,8 @@ export const withReactQuery = (Wrapped, options = {}) => { const queryClient = (res.locals.__queryClient = res.locals.__queryClient || new QueryClient(queryClientConfig)) - // Without the request object, our useServerContext hook would be able tell whether on prepass - const withoutReq = React.cloneElement(appJSX, { - req: undefined - }) - await ssrPrepass(withoutReq) + // Use `ssrPrepass` to collect all uses of `useQuery`. + await ssrPrepass(appJSX) const queryCache = queryClient.getQueryCache() const queries = queryCache.getAll().filter((q) => q.options.enabled !== false) diff --git a/packages/pwa-kit-react-sdk/src/ssr/universal/hooks/index.js b/packages/pwa-kit-react-sdk/src/ssr/universal/hooks/index.js index 897b958911..381a7fd7bd 100644 --- a/packages/pwa-kit-react-sdk/src/ssr/universal/hooks/index.js +++ b/packages/pwa-kit-react-sdk/src/ssr/universal/hooks/index.js @@ -27,7 +27,6 @@ export const useCorrelationId = () => { * @typedef {Object} ServerContext * @property {Object} req - Request object * @property {Object} res - Response object - * @property {boolean} isServerSide */ /** @@ -35,14 +34,11 @@ export const useCorrelationId = () => { * @returns {ServerContext} ServerContext object * * @example - * const {res, isServerSide} = useServerContext() - * if (isServerSide && query.error) { res.status(404) } + * const {res} = useServerContext() + * if (res && query.error) { res.status(404) } */ export const useServerContext = () => { const serverContext = useContext(ServerContext) - return { - ...serverContext, - isServerSide: Boolean(serverContext.req) - } + return serverContext }