Skip to content

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

Open
ofir-frd wants to merge 11 commits intobase_pr_30803_20260120_5105from
corrupted_pr_30803_20260120_5105
Open

[CORRUPTED] Synthetic Benchmark PR #30803 - refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0#359
ofir-frd wants to merge 11 commits intobase_pr_30803_20260120_5105from
corrupted_pr_30803_20260120_5105

Conversation

@ofir-frd
Copy link

Benchmark PR langgenius#30803

Type: Corrupted (contains bugs)

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

Compliance Violation

  • Rule: Frontend Code Must Not Use console Statements
  • Language: TypeScript
  • File: web/hooks/use-query-params.ts
lyzno1 and others added 11 commits January 10, 2026 12:51
…onment detection Centralize server/client environment detection by introducing a dedicated utility file instead of repeating `typeof window === 'undefined'` checks across the codebase. This improves code maintainability and consistency across 8 files with 15 occurrences. Closes langgenius#30802
Missed migration from the initial refactoring - removes local isClient variable definition and imports from the centralized utility.
- Update .nvmrc from 22.11.0 to 22.20.0 (lts-latest) - Update web/package.json engines from >=v22.11.0 to >=22.12.0 This fixes jsdom 27.3.0 + parse5 8.0.0 ESM compatibility issues. Node.js 22.12.0+ has require(esm) enabled by default, which allows CommonJS modules to require ES modules. Closes langgenius#30807
Removed documentation comments for server and client detection utilities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants