Skip to content

[CLEAN] Synthetic Benchmark PR #30803 - refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0#332

Open
ofir-frd wants to merge 2 commits intobase_pr_30803_20260120_8229from
clean_pr_30803_20260120_8229
Open

[CLEAN] Synthetic Benchmark PR #30803 - refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0#332
ofir-frd wants to merge 2 commits intobase_pr_30803_20260120_8229from
clean_pr_30803_20260120_8229

Conversation

@ofir-frd
Copy link

Benchmark PR langgenius#30803

Type: Clean (correct implementation)

Original PR Title: refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0
Original PR Description: ## Summary

Why not use TanStack Query's isServer?

TanStack Query exports:

export const isServer = typeof window === 'undefined' || 'Deno' in globalThis

We don't need Deno detection because:

  • Dify is a Next.js application running on Node.js
  • Deno is a different JavaScript runtime that Dify doesn't target
  • TanStack Query includes Deno check because it's a universal library supporting multiple runtimes
  • Our application code only needs to handle our own runtime environments

Changes

New File

  • web/utils/client.ts - Exports isServer and isClient boolean constants

Migrated Files

File Occurrences
featured-tools.tsx 3
featured-triggers.tsx 3
rag-tool-recommendations/index.tsx 3
embedded-chatbot/header/index.tsx 1
query-client.tsx 1
use-trigger-events-limit-modal.ts 1
list.tsx 1
gtag.ts 1
use-query-params.ts 1

Node.js Version Update

File Change
.nvmrc 22.11.022.20.0
web/package.json engines >=v22.11.0>=22.12.0

This fixes jsdom 27.3.0 + parse5 8.0.0 ESM compatibility. Node.js 22.12.0+ has require(esm) enabled by default.

Benefits

  • ✂️ DRY principle: 16 repeated checks → 1 utility function
  • 🧠 Better readability: if (isServer) is clearer than if (typeof window === 'undefined')
  • 🔄 Improved consistency: unified environment detection pattern
  • 🛠️ Easier maintenance: change logic in one place if needed
  • 🐛 Fewer typos: no risk of misspelling 'undefined'

Test plan

  • pnpm lint:fix passes
  • pnpm type-check:tsgo passes
  • pnpm test passes (27/27 tests)
  • Manual testing of affected components (localStorage persistence, SSR behavior)

Closes langgenius#30802
Closes langgenius#30807
Original PR URL: langgenius#30803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant