Skip to content

Dedupe FlowMetaProvider fetches by request params, not callback identity - #71

Open
brionmario wants to merge 1 commit into
thunder-id:mainfrom
brionmario:fix/flow-meta-duplicate-fetch
Open

Dedupe FlowMetaProvider fetches by request params, not callback identity#71
brionmario wants to merge 1 commit into
thunder-id:mainfrom
brionmario:fix/flow-meta-duplicate-fetch

Conversation

@brionmario

@brionmario brionmario commented Aug 12, 2026

Copy link
Copy Markdown
Member

Purpose

FlowMetaProvider was issuing redundant GET /flow/meta calls: 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 fetchFlowMeta callback'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 a endpoints or 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 (same baseUrl/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 a lastRequestKeyRef/inFlightRequestKeyRef pair. 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

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards.
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate flow metadata requests when equivalent settings or endpoints are reused.
    • Avoided unnecessary refetching after successful language switches.
    • Improved handling of server-provided metadata during initial loading.
  • Tests
    • Added coverage for initial metadata loading, duplicate-request prevention, and language-change refetching.

… 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.
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

FlowMetaProvider now deduplicates metadata requests by resolved endpoint and language parameters. It tracks in-flight and completed requests, handles language changes and SSR metadata, and adds tests for initial fetches, stable rerenders, and language changes.

Changes

Flow metadata deduplication

Layer / File(s) Summary
Request-key fetch tracking
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx
FlowMetaProvider derives request keys from endpoint and language parameters. It skips matching in-flight or completed requests and records successful requests.
Language, SSR, and behavior validation
packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx, packages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsx
Language switches and SSR metadata record resolved request keys. Tests cover initial fetching, equivalent endpoint rerenders, and language-change refetching.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: deduplicating FlowMetaProvider fetches by request parameters.
Description check ✅ Passed The description explains the problem, implementation, related issue, testing, and security checks; unchecked documentation and integration tests are non-critical.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx

ESLint 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.tsx

ESLint 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lift

Track 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. switchLanguage also 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 duplicate switchLanguage calls.
🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc2db2 and 477b605.

📒 Files selected for processing (2)
  • packages/react/src/contexts/FlowMeta/FlowMetaProvider.tsx
  • packages/react/src/contexts/FlowMeta/__tests__/FlowMetaProvider.test.tsx

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.

1 participant