[PR #31801] refactor!: SSR prefetch + replace Zustand with TanStack Query for systemFeatures #33413

Closed
opened 2026-02-21 20:53:14 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/31801

State: closed
Merged: No


Summary

  • SSR Prefetch: Migrate (commonLayout) to async Server Component with TanStack Query prefetchQuery + HydrationBoundary for user profile and workspace data, replacing client-side splash screen with Next.js loading.tsx convention
  • Zustand Removal: Replace useGlobalPublicStore Zustand store with direct TanStack Query hooks (useSystemFeatures, useSystemFeaturesQuery, useIsSystemFeaturesPending, useSetupStatusQuery) in hooks/use-global-public.ts, eliminating the query→store sync middleman
  • Shared SSR utilities: Extract utils/ssr-fetch.ts with React.cache()-wrapped getAuthHeaders for per-request deduplication across server components
  • Fix SetupStatusResponse.setup_at type from Date to string to match JSON API response
  • Fix setup-status.spec.ts mock target to match actual consoleClient usage

Test plan

  • Verify /apps page loads with SSR-prefetched data (no client-side loading flash)
  • Verify loading.tsx shows correctly during navigation
  • Verify all useSystemFeatures() consumers work correctly (plugin permissions, marketplace, branding, collaboration features)
  • Verify sign-in/sign-up flows still work (systemFeatures used for SSO/branding)
  • Run pnpm type-check:tsgo — passes
  • Run pnpm test for affected spec files — all pass

Breaking Changes

useGlobalPublicStore is removed. Use useSystemFeatures() from @/hooks/use-global-public instead.

**Original Pull Request:** https://github.com/langgenius/dify/pull/31801 **State:** closed **Merged:** No --- ## Summary - **SSR Prefetch**: Migrate `(commonLayout)` to async Server Component with TanStack Query `prefetchQuery` + `HydrationBoundary` for user profile and workspace data, replacing client-side splash screen with Next.js `loading.tsx` convention - **Zustand Removal**: Replace `useGlobalPublicStore` Zustand store with direct TanStack Query hooks (`useSystemFeatures`, `useSystemFeaturesQuery`, `useIsSystemFeaturesPending`, `useSetupStatusQuery`) in `hooks/use-global-public.ts`, eliminating the query→store sync middleman - **Shared SSR utilities**: Extract `utils/ssr-fetch.ts` with `React.cache()`-wrapped `getAuthHeaders` for per-request deduplication across server components - Fix `SetupStatusResponse.setup_at` type from `Date` to `string` to match JSON API response - Fix `setup-status.spec.ts` mock target to match actual `consoleClient` usage ## Test plan - [ ] Verify `/apps` page loads with SSR-prefetched data (no client-side loading flash) - [ ] Verify `loading.tsx` shows correctly during navigation - [ ] Verify all `useSystemFeatures()` consumers work correctly (plugin permissions, marketplace, branding, collaboration features) - [ ] Verify sign-in/sign-up flows still work (systemFeatures used for SSO/branding) - [ ] Run `pnpm type-check:tsgo` — passes - [ ] Run `pnpm test` for affected spec files — all pass ## Breaking Changes `useGlobalPublicStore` is removed. Use `useSystemFeatures()` from `@/hooks/use-global-public` instead.
yindo added the pull-request label 2026-02-21 20:53:14 -05:00
yindo closed this issue 2026-02-21 20:53:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33413