Skip to content

Delete only the expired eligibility cache entry instead of clearing sessionStorage - #426

Merged
greg-olivier merged 3 commits into
feature/rebrandingfrom
feature/mp-323-rb-6-stop-wiping-the-merchants-sessionstorage
Dec 2, 2026
Merged

greg-olivier merged 3 commits into
feature/rebrandingfrom
feature/mp-323-rb-6-stop-wiping-the-merchants-sessionstorage

Conversation

@greg-olivier

@greg-olivier greg-olivier commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What changes

When the eligibility cache entry for a widget is older than one hour, the widget used to call sessionStorage.clear(). That deleted every key the merchant keeps on the page, such as cart, checkout and analytics data. It also sent no request, so the widget stayed on its loader until the next add().

Now an expired entry is deleted on its own, and the request goes out as for a cache miss. The widget shows its plans after one request. The widget never calls sessionStorage.clear(), and clearCache() is removed.

A corrupt entry is handled the same way. If the stored text is not valid JSON, or its value is not an array, the entry is deleted and the widget fetches again. Before, both cases made the widget fail with a warning and show nothing, until the entry expired.

Commits

  1. Deletes the expired entry and refetches. This is the behaviour change the PR is about.
  2. Applies the same delete and refetch to corrupt entries.
  3. Moves the cache read policy from get-eligibility.ts into a new readCache(key) in eligibility-cache.ts. This commit changes no behaviour, except that the warnings for a failed read and a failed delete now share one message. readCache returns the cached plans, or null when the request must go out. getCache, deleteCache and isMoreThanOneHourAgo are no longer exported. The cache tests now call readCache and setCache, and get-eligibility.test.ts keeps only the cases about when a request goes out.

For the reviewer

  • Only a SyntaxError from JSON.parse counts as a corrupt entry. Any other storage error is rethrown and still makes getEligibility() fail with one warning, as it did before.
  • An entry without a timestamp never expires. This is unchanged.
  • The old "entry is malformed" warning is gone, because that case now refetches without a warning.
  • A failed write of the cache still makes getEligibility() fail. The next PR in the stack changes that.

Not in this PR

  • A fix in 4.x. The 4.x port keeps the old behaviour on purpose.
  • Treating a storage error as a cache miss.
  • Prefixing the cache keys and removing old entries.

🤖 Generated with Claude Code

@greg-olivier
greg-olivier added this pull request to stack #428 December 1, 2026 15:09
@greg-olivier greg-olivier changed the title feature/mp 323 rb 6 stop wiping the merchants sessionstorage Delete only the expired eligibility cache entry instead of clearing sessionStorage Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Storybook of 92fbe1b

👌 Chromatic found no visual changes to review.

@greg-olivier greg-olivier self-assigned this Dec 1, 2026
@greg-olivier
greg-olivier marked this pull request as ready for review December 1, 2026 15:18

@CamilleFljt CamilleFljt 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.

💪

greg-olivier and others added 3 commits December 2, 2026 12:21
…ring sessionStorage

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@greg-olivier
greg-olivier force-pushed the feature/mp-323-rb-6-stop-wiping-the-merchants-sessionstorage branch from 1444af9 to 92fbe1b Compare December 2, 2026 11:21
@greg-olivier
greg-olivier merged commit 7933832 into feature/rebranding Dec 2, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants