Skip to content

Conversation

@kdaviduik
Copy link
Contributor

The CartGiftCard component maintained a useRef that accumulated gift card codes client-side, but this ref was never read - only written to. This created potential for "zombie" bugs where the client and server state could diverge (the ref only grew, never shrunk when cards were removed).

Since the GiftCardCodesAdd action handles everything server-side and the UI displays gift cards directly from the GraphQL response (cart.appliedGiftCards), this client-side tracking was redundant and potentially problematic.

Removed:

  • appliedGiftCardCodes useRef (dead code - write-only)
  • saveAppliedCode function (populated unused ref)
  • Render-prop pattern with side effects in AddGiftCardForm
  • Unused FetcherWithComponents import

WHY are these changes introduced?

Fixes #0000

WHAT is this pull request doing?

HOW to test your changes?

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@shopify
Copy link
Contributor

shopify bot commented Jan 29, 2026

Oxygen deployed a preview of your kd-fix-gift-card-resurrection-bug branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment January 29, 2026 7:18 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment January 29, 2026 6:19 AM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment January 29, 2026 6:19 AM
sitemap ✅ Successful (Logs) Preview deployment Inspect deployment January 29, 2026 6:19 AM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment January 29, 2026 6:19 AM

Learn more about Hydrogen's GitHub integration.

The CartGiftCard component maintained a useRef that accumulated gift card
codes client-side, but this ref was never read - only written to. This
created potential for "zombie" bugs where the client and server state
could diverge (the ref only grew, never shrunk when cards were removed).

Since the GiftCardCodesAdd action handles everything server-side and the
UI displays gift cards directly from the GraphQL response (cart.appliedGiftCards),
this client-side tracking was redundant and potentially problematic.

Removed:
- appliedGiftCardCodes useRef (dead code - write-only)
- saveAppliedCode function (populated unused ref)
- Render-prop pattern with side effects in AddGiftCardForm
- Unused FetcherWithComponents import
@fredericoo fredericoo force-pushed the kd-fix-gift-card-resurrection-bug branch from c79dc17 to 64be556 Compare January 29, 2026 19:16
@fredericoo fredericoo marked this pull request as ready for review January 29, 2026 19:18
@fredericoo fredericoo requested a review from a team as a code owner January 29, 2026 19:18
Comment on lines 115 to 119
useEffect(() => {
if (giftCardAddFetcher.data) {
giftCardCodeInput.current!.value = '';
}
}, [giftCardAddFetcher.data]);
Copy link
Contributor

Choose a reason for hiding this comment

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

im not a fan of this either but i guess there aren’t callbacks for fetcher to reset the form

we could pass a ref to the form and call form.reset() that would give me some peace of mind but overall they do the same so whatever, lets not change for the sake of changing it

Copy link
Contributor

@fredericoo fredericoo left a comment

Choose a reason for hiding this comment

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

code looks harmless, BUT e2e tests are failing in CI and just hang forever locally – investigating which branch originated this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants