Skip to content

refactor(frontend): improve stability of data providers#4768

Merged
jog1t merged 1 commit intomainfrom
04-24-refactor_frontend_improve_stability_of_data_providers
Apr 24, 2026
Merged

refactor(frontend): improve stability of data providers#4768
jog1t merged 1 commit intomainfrom
04-24-refactor_frontend_improve_stability_of_data_providers

Conversation

@jog1t
Copy link
Copy Markdown
Contributor

@jog1t jog1t commented Apr 24, 2026

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app
Copy link
Copy Markdown

railway-app Bot commented Apr 24, 2026

🚅 Deployed to the rivet-pr-4768 environment in rivet-frontend

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web Apr 24, 2026 at 10:51 pm
frontend-inspector ❌ Build Failed (View Logs) Web Apr 24, 2026 at 10:47 pm
website ✅ Success (View Logs) Web Apr 24, 2026 at 10:45 pm
frontend-cloud ❌ Build Failed (View Logs) Web Apr 24, 2026 at 10:44 pm
mcp-hub ✅ Success (View Logs) Web Apr 24, 2026 at 10:43 pm
ladle ❌ Build Failed (View Logs) Web Apr 24, 2026 at 10:43 pm

Copy link
Copy Markdown
Contributor Author

jog1t commented Apr 24, 2026

@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

Code Review: refactor(frontend): improve stability of data providers

Overview

This PR fixes a real TanStack Router footgun: useRouteContext returns a snapshot taken at match creation time and never reflects beforeLoad results. The fix is to:

  1. Move dataProvider setup into context() (sync, captured at match creation)
  2. Re-export it from each route's loader so consumers can use useLoaderData
  3. Update all consumer hooks to call useLoaderData instead of useRouteContext

The core approach is correct and the CLAUDE.md documentation update accurately captures the new convention.


What Is Good

  • Root cause is correctly diagnosed. useRouteContext snapshots context before beforeLoad runs; useLoaderData reads post-loader data and will be properly reactive.
  • BillingUsageGauge cleanup is safe. The features.billing and route-match guards were redundant. layout.tsx lines 213 and 237 already wrap both render sites in features.billing && matchRoute(...). Removing the duplicate guards in the component is correct.
  • useDataProviderCheck is untouched. It only checks route presence via useMatchRoute, not reading loader data, so it does not need changing.
  • useEngineCompatDataProvider refactor to the explicit if/else pattern with per-branch biome-ignore comments is consistent with how useDataProvider is already written.
  • useCloudDataProvider simplification removes the from parameter override safely; all callers used the default route ID.

Concerns

1. orgs.$organization.tsx — data provider created before org validation

Before, the old beforeLoad awaited authClient.organization.getFullOrganization, threw notFound() on error, and only then created the data provider with org.data.slug (the API-validated slug).

After, context() creates the data provider synchronously with params.organization (the raw URL slug), before the org is validated in beforeLoad.

If beforeLoad throws notFound(), TanStack Router aborts navigation and the loader does not run, so there is no risk of a component rendering with a bad provider. However, the slug passed to getOrCreateOrganizationContext changed from org.data.slug to params.organization. These should be identical in practice, but if the auth service normalizes slugs (e.g., case-folding), the context cache key could differ. Worth confirming that getOrCreateOrganizationContext is slug-case-insensitive, or that the auth API always returns the slug in the same casing as the URL.

2. ns.$namespace.tsxrecordRecentVisit placement

The side effect moved from a combined beforeLoad (that also created the data provider) into a dedicated beforeLoad. This is fine functionally, but worth confirming that recordRecentVisit should still fire on every navigation to this route and not just on first provider creation. The old behavior fired it on every beforeLoad call, and the new code preserves that — just flagging as intentional.

3. CLAUDE.md bullet length

The new convention bullet is accurate but long. CLAUDE.md says to keep additions concise. Consider tightening: "Data providers: set up in context() (sync) or beforeLoad (async), always re-exported from loader as { dataProvider: context.dataProvider }. Consumer hooks use useLoaderData, never useRouteContext."


Summary

The refactor is sound. Two things worth a second look before merging:

  1. Confirm getOrCreateOrganizationContext is slug-insensitive or that the auth API always echoes back the same casing as the URL param.
  2. Confirm the recordRecentVisit call in ns.$namespace.tsx beforeLoad still fires at the correct time for your UX intent.

No blocking issues — the core fix is correct and the code is cleaner than what it replaces.

@jog1t jog1t changed the base branch from 04-16-fix_rivetkit_minor_rivetkit_debug_changes to graphite-base/4768 April 24, 2026 22:50
@jog1t jog1t force-pushed the graphite-base/4768 branch from f6d3128 to 57ecc33 Compare April 24, 2026 22:51
@jog1t jog1t force-pushed the 04-24-refactor_frontend_improve_stability_of_data_providers branch from d29f7fb to 8335087 Compare April 24, 2026 22:51
@jog1t jog1t changed the base branch from graphite-base/4768 to main April 24, 2026 22:51
@railway-app railway-app Bot temporarily deployed to rivet-frontend / rivet-pr-4768 April 24, 2026 22:51 Destroyed
Copy link
Copy Markdown
Contributor Author

jog1t commented Apr 24, 2026

Merge activity

  • Apr 24, 10:51 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 24, 10:52 PM UTC: @jog1t merged this pull request with Graphite.

@jog1t jog1t merged commit 888935e into main Apr 24, 2026
28 of 54 checks passed
@jog1t jog1t deleted the 04-24-refactor_frontend_improve_stability_of_data_providers branch April 24, 2026 22:52
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