Skip to content

fix(tanstack): serialize custom SegmentKey fields in hashSegment (#284)#356

Open
JonasJesus42 wants to merge 1 commit into
mainfrom
issue-284
Open

fix(tanstack): serialize custom SegmentKey fields in hashSegment (#284)#356
JonasJesus42 wants to merge 1 commit into
mainfrom
issue-284

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #284. hashSegment only serialized a fixed set of known fields (device, loggedIn, salesChannel, regionId, flags), so any custom dimension a site added via buildSegment was 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). Now hashSegment appends any custom key in stable-sorted order while keeping the known fields' 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. Added a describe("hashSegment") suite covering format regression, custom-field variation, stable ordering, array sorting, no flags mutation, and falsy-value omission. Also documented that the HTTP purge endpoint doesn't reach custom dimensions (a pre-existing limitation, already true for flags/tablet).

🤖 Generated with Claude Code


Summary by cubic

Fixes #284 by updating hashSegment to include custom SegmentKey fields in the cache key, preventing cross-cohort cache collisions. Known fields keep their exact token format so existing keys remain unchanged.

  • Bug Fixes
    • Serialize custom dimensions as key=value in stable-sorted order; arrays sorted; falsy values omitted.
    • Preserve historical tokens for known fields (device|auth|sc=…|r=…|f=…) and avoid mutating flags.
    • Export hashSegment and add tests for format, ordering, and custom fields.
    • Add an index signature to SegmentKey to document custom-dimension behavior.
    • Document that the HTTP purge endpoint still only covers device × salesChannel × regionId (not flags, tablet, or custom keys).

Written for commit bf47550. Summary will update on new commits.

Review in cubic

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>
@JonasJesus42
JonasJesus42 requested a review from a team July 13, 2026 13:06
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.

buildSegment: custom SegmentKey fields are silently dropped by hashSegment (cache mis-segmentation)

1 participant