Fix RequestManager de-duplication key to be stable across object key order#5781
Closed
Chaitu7032 wants to merge 1 commit intosugarlabs:masterfrom
Closed
Fix RequestManager de-duplication key to be stable across object key order#5781Chaitu7032 wants to merge 1 commit intosugarlabs:masterfrom
Chaitu7032 wants to merge 1 commit intosugarlabs:masterfrom
Conversation
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
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.
Summary
This PR fixes a subtle de-duplication issue in
RequestManagerwhere two logically identical request payloads could generate different request keys due to object property insertion order.Impact:
cachedResponsesstats more accurateThe change is intentionally small, isolated, and low risk.
Problem (Before)
generateRequestKey()was building request keys using:JSON.stringify(params)...However,
JSON.stringify()preserves object insertion order.This means the same fields assembled via different spreads or merges could stringify differently.
Result:
pendingRequestsfailed to detect duplicatesThis bug is silent: no errors, just unnecessary duplicate requests.
Fix (What Changed)
A small helper,
stableStringify(), was added to normalize request parameters before stringification:constructor === Object)JSON.stringify()generateRequestKey()now uses:stableStringify(params)... instead of rawJSON.stringify(params).Files Changed
planet/js/RequestManager.jsplanet/js/__tests__/RequestManager.test.js.How to Verify (Before vs After) ..
Before (root cause: order-dependent stringify)
Expected output:
equal? falseAfter (fixed behavior: stable request keys)
tested screenshots
before
after fix
tests
Added regression coverage to ensure:
throttledRequest()correctly de-dupes concurrent calls even when payload key order differsRun:
npm test -- planet/js/__tests__/RequestManager.test.jsRisk / Compatibility
Note:
npm testmay print an unrelated coverage parse warning from another file in the repo; theRequestManagertest suite passes and validates this change.Why this matters
This fix removes a subtle but real source of duplicate API traffic while keeping the implementation minimal, predictable, and easy to reason about.