-
Notifications
You must be signed in to change notification settings - Fork 400
fix: make visitorConsent conditional in cart operations #3720
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
336fe88
fix(hydrogen): make visitorConsent conditional in cart operations
itsjustriley 83ab81d
fix(hydrogen-react): make visitorConsent conditional in cart queries
itsjustriley bdc1d85
chore: add changeset for visitorConsent fix
itsjustriley 45c3550
refactor(hydrogen): unify CartBuilderOptions type and pull complexity…
itsjustriley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| '@shopify/hydrogen': patch | ||
| '@shopify/hydrogen-react': patch | ||
| --- | ||
|
|
||
| Fix cart operations failing on stores without `VisitorConsent` type | ||
|
|
||
| Cart operations (like `cart.setMetafields()`) were unconditionally including the `visitorConsent` parameter in GraphQL operations, even when not being used. This caused failures on stores whose Storefront API schema doesn't include the `VisitorConsent` type (older API versions or certain store configurations). | ||
|
|
||
| The `visitorConsent` parameter is now only included in cart GraphQL operations when explicitly provided. This restores compatibility with stores that don't support the `VisitorConsent` type while preserving the feature for users who need it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import {describe, it, expect} from 'vitest'; | ||
| import { | ||
| CartLineAdd, | ||
| CartCreate, | ||
| CartLineRemove, | ||
| CartLineUpdate, | ||
| CartNoteUpdate, | ||
| CartBuyerIdentityUpdate, | ||
| CartAttributesUpdate, | ||
| CartDiscountCodesUpdate, | ||
| CartQuery, | ||
| } from './cart-queries'; | ||
|
|
||
| const MOCK_FRAGMENT = '...MockFragment'; | ||
|
|
||
| describe('cart-queries', () => { | ||
| describe('visitorConsent conditional inclusion', () => { | ||
| const queries = [ | ||
| {name: 'CartLineAdd', fn: CartLineAdd}, | ||
| {name: 'CartCreate', fn: CartCreate}, | ||
| {name: 'CartLineRemove', fn: CartLineRemove}, | ||
| {name: 'CartLineUpdate', fn: CartLineUpdate}, | ||
| {name: 'CartNoteUpdate', fn: CartNoteUpdate}, | ||
| {name: 'CartBuyerIdentityUpdate', fn: CartBuyerIdentityUpdate}, | ||
| {name: 'CartAttributesUpdate', fn: CartAttributesUpdate}, | ||
| {name: 'CartDiscountCodesUpdate', fn: CartDiscountCodesUpdate}, | ||
| {name: 'CartQuery', fn: CartQuery}, | ||
| ]; | ||
|
|
||
| describe.each(queries)('$name', ({fn}) => { | ||
| it('should not include visitorConsent by default', () => { | ||
| const query = fn(MOCK_FRAGMENT); | ||
|
|
||
| expect(query).toContain('@inContext'); | ||
| expect(query).not.toContain('visitorConsent'); | ||
| expect(query).not.toContain('VisitorConsent'); | ||
| }); | ||
|
|
||
| it('should not include visitorConsent when explicitly disabled', () => { | ||
| const query = fn(MOCK_FRAGMENT, {includeVisitorConsent: false}); | ||
|
|
||
| expect(query).toContain('@inContext'); | ||
| expect(query).not.toContain('visitorConsent'); | ||
| expect(query).not.toContain('VisitorConsent'); | ||
| }); | ||
|
|
||
| it('should include visitorConsent when explicitly enabled', () => { | ||
| const query = fn(MOCK_FRAGMENT, {includeVisitorConsent: true}); | ||
|
|
||
| expect(query).toContain('@inContext'); | ||
| expect(query).toContain('$visitorConsent: VisitorConsent'); | ||
| expect(query).toContain('visitorConsent: $visitorConsent'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what was the previous behaviour before this param existed? we should default to whatever was before, right?
is there ever a world where we would want people not to include visitor consent? and should we even allow that?
these are genuine questions, im wondering if we could just hardcode it as true and include it every time
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.
The default behaviour was that it wasn't included. We added the feature to include it unconditionally based on an API change (#3408). That PR states: "Most Hydrogen storefronts do NOT need this feature. If you're using Hydrogen's analytics provider, or Shopify's Customer Privacy API, then consent is already handled automatically." So we're defaulting to the original behaviour in this PR.
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.
excellent! thanks for the comprehensive reply
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.
thank you for prompting me to double check!