fix(tanstack): serialize custom SegmentKey fields in hashSegment (#284)#356
Open
JonasJesus42 wants to merge 1 commit into
Open
fix(tanstack): serialize custom SegmentKey fields in hashSegment (#284)#356JonasJesus42 wants to merge 1 commit into
JonasJesus42 wants to merge 1 commit into
Conversation
hashSegment only serialized a fixed set of known fields (device, loggedIn, salesChannel, regionId, flags), silently dropping any custom dimension a site added via buildSegment. Requests that should land in different cache buckets shared one entry, serving the wrong cached response with no compile or runtime error. Now hashSegment appends any custom key in stable-sorted order (known fields keep their historical byte-for-byte format, so existing cache keys are unchanged), SegmentKey carries an index signature documenting the behavior, and the function is hoisted to module scope and exported for unit testing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #284.
hashSegmentonly serialized a fixed set of known fields (device,loggedIn,salesChannel,regionId,flags), so any custom dimension a site added viabuildSegmentwas silently dropped from the cache key — requests that should land in different buckets shared one entry and the worker served the wrong cached response, with no compile or runtime error (a real production incident where store/CEP selection didn't vary the PLP cache). NowhashSegmentappends any custom key in stable-sorted order while keeping the known fields' historical byte-for-byte format (so existing cache keys are unchanged),SegmentKeycarries an index signature documenting the behavior, and the function is hoisted to module scope and exported. Added adescribe("hashSegment")suite covering format regression, custom-field variation, stable ordering, array sorting, noflagsmutation, and falsy-value omission. Also documented that the HTTP purge endpoint doesn't reach custom dimensions (a pre-existing limitation, already true forflags/tablet).🤖 Generated with Claude Code
Summary by cubic
Fixes #284 by updating
hashSegmentto include customSegmentKeyfields in the cache key, preventing cross-cohort cache collisions. Known fields keep their exact token format so existing keys remain unchanged.key=valuein stable-sorted order; arrays sorted; falsy values omitted.device|auth|sc=…|r=…|f=…) and avoid mutatingflags.hashSegmentand add tests for format, ordering, and custom fields.SegmentKeyto document custom-dimension behavior.flags,tablet, or custom keys).Written for commit bf47550. Summary will update on new commits.