dify/web/utils
yyh 2833965815
refactor!: migrate commonLayout to SSR prefetch with TanStack Query hydration
BREAKING CHANGE: commonLayout is now an async Server Component that
prefetches user-profile and current-workspace on the server via
TanStack Query's prefetchQuery + HydrationBoundary pattern. This
replaces the previous purely client-side data fetching approach.

Key changes:

- **SSR data prefetch (root layout)**: prefetch systemFeatures and
  setupStatus in the root layout server component, wrap children with
  HydrationBoundary to hydrate TanStack Query cache on the client.

- **SSR data prefetch (commonLayout)**: convert commonLayout from a
  client component to an async server component that prefetches
  user-profile (with x-version/x-env response headers) and
  current-workspace. Client-side providers/UI extracted to a new
  layout-client.tsx component.

- **Add loading.tsx (Next.js convention)**: add a Next.js loading.tsx
  file in commonLayout that shows a centered spinner. This replaces the
  deleted Splash component but works via Next.js built-in Suspense
  boundary for route segments, not a client-side overlay.

- **Extract shared SSR fetch utilities (utils/ssr-fetch.ts)**: create
  serverFetch (unauthenticated) and serverFetchWithAuth (with cookie
  forwarding + CSRF token). getAuthHeaders is wrapped with React.cache()
  for per-request deduplication across multiple SSR fetches.

- **Refactor AppInitializer**: split single monolithic async IIFE effect
  into three independent useEffects (oauth tracking, education verify,
  setup status check). Use useReducer for init flag, useRef to prevent
  duplicate tracking in StrictMode. Now reads setupStatus from TanStack
  Query cache (useSetupStatusQuery) instead of fetching independently.

- **Refactor global-public-context**: move Zustand store sync from
  queryFn side-effect to a dedicated useEffect, keeping queryFn pure.
  fetchSystemFeatures now simply returns the API response.

- **Fix usePSInfo SSR crash**: defer globalThis.location access from
  hook top-level to callback execution time via getDomain() helper,
  preventing "Cannot read properties of undefined" during server render.

- **Remove Splash component**: delete the client-side loading overlay
  that relied on useIsLogin polling, replaced by Next.js loading.tsx.

- **Remove staleTime/gcTime overrides in useUserProfile**: allow the
  SSR-prefetched data to be reused via default cache policy instead of
  forcing refetch on every mount.

- **Revert middleware auth guard**: remove the cookie-based session
  check in proxy.ts that caused false redirects to /signin for
  authenticated users (Dify's auth uses token refresh, not simple
  cookie presence).
2026-02-01 18:29:41 +08:00
..
app-redirection.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
app-redirection.ts feat: introduce trigger functionality (#27644) 2025-11-12 17:59:37 +08:00
classnames.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
classnames.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
client.ts refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0 (#30803) 2026-01-12 12:57:43 +08:00
clipboard.spec.ts refactor(web): migrate to Vitest and esm (#29974) 2025-12-22 16:35:22 +08:00
clipboard.ts fix: resolve clipboard.writeText failure under HTTP protocol (#12936) 2025-01-22 15:18:23 +08:00
completion-params.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
completion-params.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
context.spec.ts chore: lint require and how to import react (#30041) 2025-12-23 18:02:10 +08:00
context.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
download.spec.ts refactor(web): consolidate download helpers (#31664) 2026-01-29 16:02:49 +08:00
download.ts feat: Download the uploaded files (#31068) 2026-01-19 16:48:13 +08:00
draft-07.json feat: Add customized json schema validation (#25408) 2025-09-09 15:15:32 +08:00
emoji.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
emoji.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
encryption.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
error-parser.ts feat: introduce trigger functionality (#27644) 2025-11-12 17:59:37 +08:00
format.spec.ts refactor(web): consolidate download helpers (#31664) 2026-01-29 16:02:49 +08:00
format.ts refactor(web): consolidate download helpers (#31664) 2026-01-29 16:02:49 +08:00
get-icon.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
get-icon.ts Introduce Plugins (#13836) 2025-02-17 17:05:13 +08:00
gtag.ts refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0 (#30803) 2026-01-12 12:57:43 +08:00
index.spec.ts refactor(query-state): migrate query param state management to nuqs (#30184) 2025-12-29 11:24:54 +08:00
index.ts feat(web): migrate from es-toolkit/compat to native es-toolkit (#30244) (#30246) 2025-12-31 11:13:22 +08:00
mcp.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
mcp.ts removing horus eye and adding mcp icon (#25323) 2025-10-10 17:00:03 +08:00
model-config.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
model-config.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
navigation.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
navigation.ts CI: add TS indentation check via esLint (#24810) 2025-09-01 15:31:59 +08:00
permission.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
permission.ts fix: add dataset edit permissions (#13223) 2025-02-06 14:26:16 +08:00
plugin-version-feature.spec.ts refactor(web): migrate to Vitest and esm (#29974) 2025-12-22 16:35:22 +08:00
plugin-version-feature.ts feat: the frontend part of mcp (#22131) 2025-07-10 14:14:02 +08:00
semver.spec.ts feat: the frontend part of mcp (#22131) 2025-07-10 14:14:02 +08:00
semver.ts feat: the frontend part of mcp (#22131) 2025-07-10 14:14:02 +08:00
server-only-context.ts feat: init rsc support for translation (#30596) 2026-01-06 13:23:03 +08:00
setup-status.spec.ts refactor(web): setup status caching (#30798) 2026-01-13 16:59:49 +08:00
setup-status.ts refactor(web): setup status caching (#30798) 2026-01-13 16:59:49 +08:00
ssr-fetch.ts refactor!: migrate commonLayout to SSR prefetch with TanStack Query hydration 2026-02-01 18:29:41 +08:00
storage.spec.ts test(web): add unit tests for storage utility 2026-01-28 15:12:11 +08:00
storage.ts feat(web): add resizable sidebar to skill page with localStorage persistence 2026-01-28 15:12:11 +08:00
time.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
time.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
timezone.json chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
timezone.ts Fix/app logs today filter (#689) 2023-07-31 13:30:04 +08:00
tool-call.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
tool-call.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
urlValidation.spec.ts test: adding some web tests (#27792) 2025-11-04 21:06:44 +08:00
urlValidation.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
validators.spec.ts test: adding some web tests (#27792) 2025-11-04 21:06:44 +08:00
validators.ts feat: Add customized json schema validation (#25408) 2025-09-09 15:15:32 +08:00
var.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00
var.ts fix: remove hardcoded 48-character limit from text inputs (#30156) 2026-01-15 17:43:00 +08:00
zod.spec.ts chore(web): new lint setup (#30020) 2025-12-23 16:58:55 +08:00