Repository navigation
[Refactor] Build cookie record declaratively in parseCookies - #8954
Draft
github-actions[bot] wants to merge 1 commit into
Draft
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
WHY are these changes introduced?
parseCookiesbuilds its result by declaring an empty record and mutating it inside aforEach, while its siblingserializeCookiesin 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
parseCookiesto build the record withflatMapandObject.fromEntries, so the key/value pairs are produced as data and the record is constructed in one expression. Destructuring the regex match replaces the positionalparts[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?
Browse the previewed storefront and confirm the session is preserved across requests (no repeated login or lost preview theme).
Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add