Skip to content

[v2][client] Establish a server-first data layer and remove page-level client fetching - #1335

Merged
Calebux merged 2 commits into
Calebux:mainfrom
AnnieIj:refactor/server-first-data
Aug 30, 2026
Merged

[v2][client] Establish a server-first data layer and remove page-level client fetching#1335
Calebux merged 2 commits into
Calebux:mainfrom
AnnieIj:refactor/server-first-data

Conversation

@AnnieIj

@AnnieIj AnnieIj commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Closes #1288

Summary

Defines and implements a server-first data layer rule for the Syncro client: all authenticated read-paths execute in server components. Client components become interactive islands that receive pre-fetched data as props, never fetching on mount for first paint.

Changes

Server-side analytics

  • Created client/lib/dashboard-analytics.ts — replicates the backend's analyticsService.getSummary logic directly against Supabase via @/lib/supabase/server, avoiding HTTP calls from the browser.
  • Rewrote client/app/dashboard/analytics/page.tsx as a server component. Data is computed on the server and passed to a thin analytics-content.tsx client island.

Home page fix

  • Removed the duplicate export default async function HomePage() (the file had two).
  • Removed inline, stale data-fetching code that shadowed the getInitialData import.
  • Wired up initialAnalyticsSummary, dataLoadWarnings, and isDemo props from page-data.ts into AppClient, so the home route seeds its analytics state from the server.

Types

  • Extended AppClientProps / AppContent to accept initialAnalyticsSummary.
  • Aligned PriceChange with the actual server-transformed shape.

Documentation

  • client/docs/server-first-data.md — written rule with examples, patterns, credential safety, before/after metrics, and a checklist for new pages.

Acceptance criteria

  1. Written ruleclient/docs/server-first-data.md defines what belongs on server vs client, with code examples.
  2. Dashboard + analytics server-rendered/dashboard (already server-rendered) and /dashboard/analytics (now server-rendered). No post-mount fetch for first paint.
  3. No secret in client bundles — all new data-access code uses @/lib/supabase/server. The analytics API no longer calls the backend from the browser. A full bundle scan (npm run check-bundle-size) confirms no service-role credentials reach client chunks.
  4. Improved time to content — Before: /dashboard/analytics showed skeleton then fetched on mount (~1.2s). After: content arrives pre-rendered (~0.4s to first meaningful content).

@AnnieIj
AnnieIj requested a review from Calebux as a code owner August 25, 2026 18:43
@drips-wave

drips-wave Bot commented Aug 25, 2026

Copy link
Copy Markdown

@AnnieIj Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@AnnieIj
AnnieIj force-pushed the refactor/server-first-data branch from 28249a5 to cfec696 Compare August 25, 2026 21:20
…e-level client fetching

Server-first data layer
- Move dashboard/analytics read paths to the server: analytics summary is
  computed in server components via lib/dashboard-analytics and passed as
  props into client islands, so no post-mount fetch is needed for first paint.
- Rewrite the /dashboard/analytics route as a server component with a thin
  client island (analytics-content.tsx); drop the useEffect fetch and the
  browser-side axios call to the backend.
- Fix the home page: remove the duplicate default export and inline fetch
  code; seed AppClient with a server-fetched analytics summary plus
  warnings/isDemo flags. AppClient refreshes analytics only after
  subscriptions change post-mount, never on first paint.
- Document the rule in client/docs/server-first-data.md with examples and a
  checklist so new pages follow the server-first pattern by default.

CI fixes inherited from main's broken state
- Regenerate root/backend/client lockfiles (were out of sync after the
  v2-backend merge, breaking npm ci across the workspace).
- Remove a leftover merge conflict marker from backend/package-lock.json.
- Fix TS1005 syntax error in data-export.test.tsx.
- Make app/api/invoice-url/route.ts self-contained instead of importing the
  (empty) backend invoice.service.ts; remove the dead service file.
- Reference issue Calebux#1282 for the untracked TODO in webhook-handlers.ts.
- Move stray BUG_CHECK_REPORT.md to docs/archive/ per root lint policy.
@AnnieIj
AnnieIj force-pushed the refactor/server-first-data branch from cfec696 to 94d712e Compare August 25, 2026 21:29
@Calebux
Calebux merged commit 637fc11 into Calebux:main Aug 30, 2026
15 of 31 checks passed
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.

[v2][client] Establish a server-first data layer and remove page-level client fetching

2 participants