-
Notifications
You must be signed in to change notification settings - Fork 146
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
Make commerce-sdk-react
Work Server-Side 💪🏻
#734
Conversation
packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js
Outdated
Show resolved
Hide resolved
commerce-sdk-reack
Work Server-Side 💪🏻commerce-sdk-react
Work Server-Side 💪🏻
packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js
Outdated
Show resolved
Hide resolved
packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js
Outdated
Show resolved
Hide resolved
packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js
Outdated
Show resolved
Hide resolved
packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js
Show resolved
Hide resolved
Since we plan to remove the QueryClientProvider in our commerce hooks. See PR #734
packages/test-commerce-sdk-react/app/components/_app-config/index.tsx
Outdated
Show resolved
Hide resolved
|
||
export const withReactQuery = (Wrapped) => { | ||
export const withReactQuery = (Wrapped, options = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some jsdoc comment here to document the HOC, since it's gonna be public facing.
packages/pwa-kit-react-sdk/src/ssr/universal/components/with-react-query/index.js
Outdated
Show resolved
Hide resolved
windowSpy.mockRestore() | ||
}) | ||
|
||
test('Renders correctly', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a duplicate test
Idea isn't fully baked yet
Co-authored-by: Vincent Marta <[email protected]>
Co-authored-by: Vincent Marta <[email protected]>
Co-authored-by: Vincent Marta <[email protected]>
Co-authored-by: Vincent Marta <[email protected]>
Co-authored-by: Vincent Marta <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my end, there are a few remaining minor comments that have not been resolved yet. But overall, this PR looks good to me now.
queries: { | ||
retry: !server // Only retry when on the client. | ||
}, | ||
mutations: { | ||
retry: !server // Only retry when on the client. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad example, this means never retry on the server, infinite retry on the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamraya yeah, let's fix this readme next week.
* 1st attempt at disabling retry when seeing validation error * Make sure the retries would stop * Add todos * Add comment * Some refactoring and typing * Remove some guards * Add comments * Remove comments * Demonstrate user error * React Query's retries are now done only for 5xx server errors * For easier debugging * Revert change Since we plan to remove the QueryClientProvider in our commerce hooks. See PR #734 * Disable retries And set the option at the individual query level. * Revert adding query options on individual queries * Remove todo We can't use ResponseError yet, since it's not exported by the isomorphic sdk. * Create a new page to see the errors * Test validation error
Description
This the server-side support for
react-query
being merged into the SDK in this #724. It was important that we prove that thecommerce-sdk-react
hooks work was compatible. In this PR I make the required changes to ensure that any hooks used via thecommerce-sdk-react
module are executed server side.I have left comments on part of this PR that I would like feedback on. So please pay special attention to those.
Why didn't this work after imply updating the sdk?
The reason this didn't work, is the
commerce-sdk-react
provider was itself using a react query provider. This provider was in conflict with the one supplied by the SDK. This meant that any hooks that we used used the client in the first provider it could find in its component hierarchy. This was the one defined in thecommerce-sdk-react
. Unfortunately the SDK does not know anything about this one and isn't able to track and execute the queries made by the hooks within it. This is the reason that it was required to be removed.Changes
withReactQuery
HoC from the SDKcommerce-sdk-react
readme on how its used in and out of a PWA-Kit application.withReactQuery
to consume options for setting the clients configuration.How to Test-Drive This PR
npm ci
npm start
General
TODOs
commerce-sdk-react