Skip to content

[Refactor] Build cookie record declaratively in parseCookies - #8954

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor-maintenance-39347363624
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor-maintenance-39347363624

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

parseCookies builds its result by declaring an empty record and mutating it inside a forEach, while its sibling serializeCookies in the same file is already written declaratively. The imperative accumulator makes the reader track mutation across the callback to understand what the function returns.

WHAT is this pull request doing?

Rewrites parseCookies to build the record with flatMap and Object.fromEntries, so the key/value pairs are produced as data and the record is constructed in one expression. Destructuring the regex match replaces the positional parts[1]/parts[2] indexing, and the return type is now stated explicitly.

Behavior is unchanged: entries without a key are still skipped, keys and values are still trimmed, a missing value still becomes an empty string, and repeated keys still resolve to the last occurrence.

How to manually test your changes?

shopify theme dev

Browse the previewed storefront and confirm the session is preserved across requests (no repeated login or lost preview theme).

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

Replace the mutating forEach accumulator with flatMap and
Object.fromEntries, matching the declarative style of the
sibling serializeCookies helper.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

0 participants