Dedupe FlowMetaProvider fetches by request params, not callback identity - #71
Dedupe FlowMetaProvider fetches by request params, not callback identity#71brionmario wants to merge 1 commit into
Conversation
… identity Redundant meta fetches happened whenever endpoints or the i18n context were recreated with equivalent content across renders: fetchFlowMeta's identity changed even though the request itself hadn't, and the previous guard only caught same-reference re-fires. Keys the dedup on the resolved baseUrl/url/id/language instead, so equivalent-content re-renders are skipped while a genuine language switch still fetches.
📝 WalkthroughWalkthrough
ChangesFlow metadata deduplication
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsxESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. packages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsxESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx (1)
105-129: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftTrack all flow-meta requests in one per-key registry.
A request for key A can still be pending when a request for key B starts. When A completes, Line 127 clears the single in-flight slot and Line 128 clears loading while B remains pending. A later equivalent rerender can then dispatch B again.
switchLanguagealso bypasses this tracking, so concurrent calls for the same language always dispatch duplicate requests.
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx#L105-L129: track active requests per key and only clear loading or publish state for the active request.packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx#L139-L170: route language-switch requests through the same request-key guard before dispatch.packages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsx#L61-L131: add deferred-promise tests for overlapping keys and duplicateswitchLanguagecalls.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx` around lines 105 - 129, Update packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx:105-129 to maintain active requests in a per-request-key registry, preventing duplicate dispatches and ensuring completion only clears loading or publishes metadata for the still-active request; preserve independent concurrent requests for different keys. Update switchLanguage in packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx:139-170 to use the same request-key guard and registry. Add deferred-promise coverage in packages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsx:61-131 for overlapping keys and duplicate switchLanguage calls.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx`:
- Around line 105-129: Update
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx:105-129 to maintain
active requests in a per-request-key registry, preventing duplicate dispatches
and ensuring completion only clears loading or publishes metadata for the
still-active request; preserve independent concurrent requests for different
keys. Update switchLanguage in
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx:139-170 to use the
same request-key guard and registry. Add deferred-promise coverage in
packages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsx:61-131
for overlapping keys and duplicate switchLanguage calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 05c9b91d-9705-44eb-ae3d-739e5cb4937b
📒 Files selected for processing (2)
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsxpackages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsx
Purpose
FlowMetaProviderwas issuing redundantGET /flow/metacalls: for example, three identical requests in a row while landing on the sign-in page after a Console/Gate sign-out round trip.Its dedup guard compared the
fetchFlowMetacallback's reference against the last dispatched one. That only catches a React StrictMode re-mount firing the same closure twice. It does nothing when a consumer re-renders with aendpointsor i18n context object that's a new instance but has the same content (e.g. a config object rebuilt each render) —fetchFlowMeta's identity changes even though the actual request (samebaseUrl/url/id/language) hasn't, so the guard lets it through and fires again.Approach
Keys the dedup on the resolved request itself (
baseUrl,url,applicationId,language) instead of the callback reference, tracked via alastRequestKeyRef/inFlightRequestKeyRefpair. An in-flight or already-fetched request with the same key is skipped; a genuinely different request (e.g. an explicit language switch) still fetches normally.Related Issues
Related PRs
Checklist
breaking changelabel added.Security checks
Summary by CodeRabbit