Skip to content
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

fix: move cart creation out of trigger #2572

Merged
merged 8 commits into from
Jul 27, 2020

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Jul 22, 2020

Description

For some reason the cart trigger owns cart creation. When the component mounts it invokes a "getCartDetails" action, which in turn checks for existence of a cart id and if it doesn't find one, calls the "createCart" action, which does another check for cart id and if it also doesn't find one, invokes a mutation to create a cart.

This could be simpler. We can move cart creation to the cart context provider.

Related Issue

Closes PWA-776.

Acceptance

Verification Stakeholders

Specification

Verification Steps

  1. Clear cache and refresh. A cart id should be fetched (via createCart) from the context provider instead of the trigger.
  2. Log in. In the dev tools, modify your signin_token to invalidate it (remove a character).
  3. Refresh the page. You should see errors logged in console from graphql about unauthorized access, but then you should see those queries be remade with a valid cart id and the user token should be removed.

Screenshots / Screen Captures (if appropriate)

Checklist

  • I have added tests to cover my changes, if necessary.
  • I have updated the documentation accordingly, if necessary.

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jul 22, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-776.

Generated by 🚫 dangerJS against 141e644

@devops-pwa-codebuild
Copy link
Collaborator

devops-pwa-codebuild commented Jul 22, 2020

Performance Test Results

The following fails have been reported by WebpageTest. These numbers indicates a possible performance issue with the PR which requires further manual testing to validate.

https://pr-2572.pwa-venia.com : LH Performance Expected 0.85 Actual 0.52, LH Best Practices Expected 1 Actual 0.92, WPT Cache Expected 90 Actual 83.333333333333
https://pr-2572.pwa-venia.com/venia-tops.html : LH Performance Expected 0.75 Actual 0.29, LH Best Practices Expected 1 Actual 0.92
https://pr-2572.pwa-venia.com/valeria-two-layer-tank.html : LH Performance Expected 0.8 Actual 0.41, LH Accessibility Expected 0.9 Actual 0.89, LH Best Practices Expected 1 Actual 0.92, WPT Cache Expected 65 Actual 50

query getCartDetails($cartId: String!) {
cart(cart_id: $cartId) @connection(key: "Cart") {
# The purpose of this query is to check that the user is authorized
# to query on the current cart. Just fetch "id" to keep it small.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good explanation.

@sirugh sirugh added the version: Patch This changeset includes backwards compatible bug fixes. label Jul 23, 2020
revanth0212
revanth0212 previously approved these changes Jul 23, 2020
@revanth0212
Copy link
Contributor

revanth0212 commented Jul 23, 2020

I can see that the error message is being logged, kudos to that.

image

Followup question, should we change the errorLink function in venia-concept/src/index.js to better represent locations object instead of [object Object].

I don't want to scope creep here but if you are willing to, that would be great.

Co-authored-by: Revanth Kumar Annavarapu <[email protected]>
@@ -32,6 +32,7 @@
"@apollo/react-hooks": "~3.1.2",
"@babel/runtime": "~7.4.2",
"apollo-client": "~2.6.4",
"graphql-tag": "~2.10.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I meant to bring this up when I mentioned that this was the first query in peregrine. 💯

@dpatil-magento dpatil-magento merged commit fc3fcf9 into develop Jul 27, 2020
@dpatil-magento dpatil-magento deleted the rugh/move-cart-creation-out-of-trigger branch July 27, 2020 15:36
@sirugh sirugh restored the rugh/move-cart-creation-out-of-trigger branch April 26, 2021 16:29
@sirugh sirugh deleted the rugh/move-cart-creation-out-of-trigger branch April 26, 2021 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine pkg:venia-ui version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants