-
Notifications
You must be signed in to change notification settings - Fork 281
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
Cannot call multiple useCart callbacks consecutively #685
Comments
Should you be |
Yes, I have that typo in my test :) . However, even when adding it this still happens. I created sample repository where test can reproduce this issue: https://github.com/urgoringo/test-shopify-storefront/ It seems that status is Also, closed discussion about this to avoid duplication: #678 |
Could you check something like this: test("when calling line remove and line add the latter is ignored", async () => {
const { result } = renderCart();
act(() => result.current.cartCreate({}));
await waitFor(() => {
expect(result.current.status).toBe("idle");
});
await act(() => {
result.current.linesAdd([
{
merchandiseId: "gid://shopify/ProductVariant/44671043141922",
quantity: 1,
},
]);
});
await waitFor(() => {
console.log(result.current.status);
expect(result.current.status).toBe("idle");
});
console.log("Going to remove line", new Date());
await act(async () => {
result.current.linesRemove(result.current.lines.map((it) => it.id));
});
await waitFor(() => {
expect(result.current.status).toBe("idle");
});
await act(() => {
result.current.linesAdd([
{
merchandiseId: "gid://shopify/ProductVariant/44671043141922",
quantity: 20,
},
]);
});
await waitFor(() => {
expect(result.current.status).toBe("idle");
});
await waitFor(() => {
expect(result.current.totalQuantity).toBe(20);
});
}); from you repo, I saw you are having |
@lordofthecactus yes, indeed the test will then pass. However, in my case I want to call multiple I have updated the scenario in another test: https://github.com/urgoringo/test-shopify-storefront/blob/main/useCustomCart.test.tsx Is there any way how to handle that? Also, somewhat related issue is when I want to make some changes to cart just before I redirect user to checkout. How am I supposed to make sure that these last changes have been made successfully before doing the redirect to checkout page? If all |
What I ended up doing is writing another custom context component (as a child of the I agree that the functions exposed by |
Thanks you @Rahza! I used |
What is the location of your example repository?
No response
Which package or tool is having this issue?
hydrogen-react
What version of that package or tool are you using?
2023.1.6
What version of Remix are you using?
No response
Steps to Reproduce
Hello. I'm trying to execute multiple operations in a sequence using the
useCart
hook e.g.cartAttributesUpdate
andlinesRemove
.However, it seems only the first operation gets executed. I also tried a solution where I'm "sleeping" until cart.status === "idle" before calling another callback. This doesn't work either for some reason.
Am I missing something or my use case is not supported by the library?
I can reproduce the error with following test:
Expected Behavior
When calling multiple callbacks in a row from my custom hook then both callbacks get executed. If it's not allowed to executed multiple updates in parallel then
useCart
API could offer a way to wait until the previous update has completed.Actual Behavior
Only the first callback gets executed and the subsequent one is ignored.
The text was updated successfully, but these errors were encountered: