refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0#30803
refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0#30803
Conversation
…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 #30802
Summary of ChangesHello @lyzno1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the web application's environment detection mechanism by consolidating server-side and client-side checks into a dedicated utility. The primary goal is to standardize how the application determines its runtime context, moving away from repetitive and verbose Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors environment detection by introducing isServer and isClient utilities, which significantly improves code consistency and maintainability. The implementation is solid, and the changes have been applied correctly across multiple files. My review includes a few suggestions to further refine the code by removing some redundant logic that became apparent through this refactoring and a small improvement to the new utility file.
web/app/components/workflow/block-selector/rag-tool-recommendations/index.tsx Show resolved Hide resolved
Missed migration from the initial refactoring - removes local isClient variable definition and imports from the centralized utility.
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized environment detection utility to replace scattered typeof window === 'undefined' checks across the codebase. The refactor consolidates server/client detection logic into a single source of truth, improving maintainability and code consistency.
Changes:
- Created new utility file
web/utils/client.tsexportingisServerandisClientconstants - Replaced 15 inline environment checks with imports from the new utility across 8 files
- Updated localStorage persistence logic and SSR guards to use the centralized utility
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
web/utils/client.ts | New utility file defining isServer and isClient constants with documentation |
web/utils/gtag.ts | Replaced inline window check with isServer for Google Analytics guard |
web/hooks/use-query-params.ts | Updated query parameter clearing function to use isServer |
web/context/query-client.tsx | Updated query client instantiation guard to use isServer |
web/context/hooks/use-trigger-events-limit-modal.ts | Updated modal hook's SSR guard to use isServer |
web/app/components/workflow/block-selector/rag-tool-recommendations/index.tsx | Replaced localStorage access guards with isServer in collapse state management |
web/app/components/workflow/block-selector/featured-triggers.tsx | Updated collapse state persistence guards to use isServer |
web/app/components/workflow/block-selector/featured-tools.tsx | Updated collapse state persistence guards to use isServer |
web/app/components/base/chat/embedded-chatbot/header/index.tsx | Replaced inline isClient definition with import from utility |
web/app/components/apps/list.tsx | Updated query parameter normalization guard to use isServer |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- 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 #30807
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
Removed documentation comments for server and client detection utilities.
Summary
isServer/isClientutility at/web/utils/client.tstypeof window === 'undefined'across 9 files to use the new utilityWhy not use TanStack Query's
isServer?TanStack Query exports:
We don't need Deno detection because:
Changes
New File
web/utils/client.ts- ExportsisServerandisClientboolean constantsMigrated Files
featured-tools.tsxfeatured-triggers.tsxrag-tool-recommendations/index.tsxembedded-chatbot/header/index.tsxquery-client.tsxuse-trigger-events-limit-modal.tslist.tsxgtag.tsuse-query-params.tsNode.js Version Update
.nvmrc22.11.0→22.20.0web/package.jsonengines>=v22.11.0→>=22.12.0This fixes jsdom 27.3.0 + parse5 8.0.0 ESM compatibility. Node.js 22.12.0+ has
require(esm)enabled by default.Benefits
if (isServer)is clearer thanif (typeof window === 'undefined')'undefined'Test plan
pnpm lint:fixpassespnpm type-check:tsgopassespnpm testpasses (27/27 tests)Closes #30802
Closes #30807