Skip to content

fix: prevent using stale address data - #358

Open
joerivanveen wants to merge 3 commits into
mainfrom
fix/prevent-using-stale-address-data
Open

fix: prevent using stale address data#358
joerivanveen wants to merge 3 commits into
mainfrom
fix/prevent-using-stale-address-data

Conversation

@joerivanveen

@joerivanveen joerivanveen commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

INT-1680

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.74%. Comparing base (87f7cd1) to head (ed14a3f).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ery-options/src/listeners/updateDeliveryOptions.ts 25.00% 0 Missing and 3 partials ⚠️
...heckout-common/src/listeners/updateCheckoutForm.ts 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #358      +/-   ##
==========================================
- Coverage   82.79%   82.74%   -0.06%     
==========================================
  Files         689      689              
  Lines       11590    11591       +1     
  Branches      835      842       +7     
==========================================
- Hits         9596     9591       -5     
+ Misses       1170     1168       -2     
- Partials      824      832       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joerivanveen
joerivanveen force-pushed the fix/prevent-using-stale-address-data branch from 50ad6a9 to 4dd3c3a Compare July 7, 2026 13:04
@joerivanveen
joerivanveen marked this pull request as ready for review July 9, 2026 10:07
@joerivanveen
joerivanveen requested review from a team and a lite review from Copilot July 9, 2026 10:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a checkout bug where delivery options could be resolved against a previous (stale) address selection when toggling “ship to different address”, leading to incorrect country-based delivery option behavior.

Changes:

  • Update updateCheckoutForm to derive addressType from the freshly transformed form data (instead of a lagging DOM read).
  • Update updateDeliveryOptions to compare the effective country of the active address in each state when deciding whether to reset/refresh context.
  • Add a Vitest regression suite covering address-type toggling and context refetch behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.ts Switches country comparison to use active address per-state to avoid stale DOM-derived addressType.
libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts Adds regression tests for address-type toggling and conditional context refetching.
libs/checkout-common/src/listeners/updateCheckoutForm.ts Ensures addressType is computed from the just-read form data to prevent “one event behind” state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 27 to +31
if (checkout.state.addressTypes.includes(key as AddressType)) {
return;
}

transformedData[key as PdkField] = getEntry(data, value as string);
(transformedData as Record<PdkField, string>)[key as PdkField] = getEntry(data, value as string);
Copilot AI review requested due to automatic review settings July 10, 2026 08:01
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 43cec9a to 7f694a3 Compare July 10, 2026 08:01
@joerivanveen
joerivanveen removed the request for review from Copilot July 10, 2026 08:01
@myparcel-bot myparcel-bot Bot added the approved (Auto) label Jul 14, 2026
Copilot AI review requested due to automatic review settings July 16, 2026 11:11
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 7f694a3 to 5f42081 Compare July 16, 2026 11:11
@joerivanveen
joerivanveen removed the request for review from Copilot July 16, 2026 11:11
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 5f42081 to 40761d6 Compare July 17, 2026 08:56
Copilot AI review requested due to automatic review settings July 17, 2026 08:56
@joerivanveen
joerivanveen removed the request for review from Copilot July 17, 2026 08:56
Copilot AI review requested due to automatic review settings July 17, 2026 09:09
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 40761d6 to 63cfd14 Compare July 17, 2026 09:09
@joerivanveen
joerivanveen removed the request for review from Copilot July 17, 2026 09:09
Copilot AI review requested due to automatic review settings July 20, 2026 08:00
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 63cfd14 to 1d43ef5 Compare July 20, 2026 08:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +56 to +58
// Fails today: shows 'NL'. getDeliveryOptionsAddress reads the committed addressType, but updateCheckoutForm
// computes that from getAddressType() reading the *previous* form, so it lags one event behind the DOM.
expect(currentDeliveryCc()).toBe(SHIPPING_CC);
Comment on lines +60 to +61
// Turn the checkbox off again: should immediately fall back to billing (NL). Today it shows the lagged 'FR'.
await changeAddressTypeTo(AddressType.Billing);
Copilot AI review requested due to automatic review settings July 20, 2026 08:11
Copilot AI review requested due to automatic review settings August 5, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts:57

  • These comments are now misleading after the fix: the test should describe the previous buggy behavior as historical ("previously"/"regression"), not as something that still fails today.
    // Fails today: shows 'NL'. getDeliveryOptionsAddress reads the committed addressType, but updateCheckoutForm
    // computes that from getAddressType() reading the *previous* form, so it lags one event behind the DOM.

libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts:60

  • This comment refers to the buggy behavior as happening "Today", but the PR fixes it. Rephrase to indicate the behavior occurred previously to avoid confusion when the test passes.
    // Turn the checkbox off again: should immediately fall back to billing (NL). Today it shows the lagged 'FR'.

Copilot AI review requested due to automatic review settings August 5, 2026 09:28
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 250d505 to 72621f6 Compare August 5, 2026 09:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (3)

libs/checkout-common/src/listeners/updateCheckoutForm.ts:32

  • The second loop filters out address-type keys based on checkout.state.addressTypes. If an address type is disabled via config.hasAddressType() (so it’s not in addressTypes), its key (e.g. 'shipping') will fall through and be treated as a PdkField, overwriting the nested address object with a string. This can corrupt transformedData and break later reads like form[AddressType.Shipping][...].
  Object.entries(config.formData).forEach(([key, value]) => {
    if (checkout.state.addressTypes.includes(key as AddressType)) {
      return;
    }

    (transformedData as Record<PdkField, string>)[key as PdkField] = getEntry(data, value as string);
  });

libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts:57

  • These test comments are written as time-relative (“Fails today…”, “Today it shows…”). Once the fix is merged, they’ll become inaccurate and confusing for future readers; it’s better to describe the regression/behavior neutrally.
    // Fails today: shows 'NL'. getDeliveryOptionsAddress reads the committed addressType, but updateCheckoutForm
    // computes that from getAddressType() reading the *previous* form, so it lags one event behind the DOM.

libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts:60

  • Same as above: this comment is time-relative (“Today it shows…”). Prefer a neutral description so the test remains accurate over time.
    // Turn the checkbox off again: should immediately fall back to billing (NL). Today it shows the lagged 'FR'.

Copilot AI review requested due to automatic review settings August 5, 2026 09:36
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 72621f6 to 7bd3dec Compare August 5, 2026 09:36
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 7bd3dec to 7032d8e Compare August 5, 2026 09:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 5, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 6, 2026 10:16
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 7032d8e to 6d504f4 Compare August 6, 2026 10:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 6, 2026 14:07
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 6d504f4 to 3ef1a58 Compare August 6, 2026 14:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts:60

  • This comment refers to "Today" showing a lagged value; after the fix it should be phrased historically to avoid becoming misleading documentation.
    // Turn the checkbox off again: should immediately fall back to billing (NL). Today it shows the lagged 'FR'.

libs/checkout-delivery-options/src/listeners/updateDeliveryOptions.spec.ts:57

  • Test comment says "Fails today" and describes the pre-fix behavior. After this change lands, that wording becomes inaccurate and can confuse future readers when the test passes.
    // Fails today: shows 'NL'. getDeliveryOptionsAddress reads the committed addressType, but updateCheckoutForm
    // computes that from getAddressType() reading the *previous* form, so it lags one event behind the DOM.

Copilot AI review requested due to automatic review settings August 8, 2026 18:13
@myparcel-bot
myparcel-bot Bot force-pushed the fix/prevent-using-stale-address-data branch from 3ef1a58 to ed14a3f Compare August 8, 2026 18:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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

Labels

approved (Auto)

Development

Successfully merging this pull request may close these issues.

4 participants