From 288a828d1aeaa0cbcabd6db9935b44a53064d236 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Thu, 27 Nov 2025 04:44:07 +1000 Subject: [PATCH] fix(ui): correct SSR check logic in useRadioGroup hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed SSR detection: only return defaults when `window === undefined` (SSR) - Previous version had inverted logic that threw errors in browser - Maintains runtime validation in browser while allowing SSR builds - Fixes Next.js build failures and browser errors on playground page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/ui/src/Radio/RadioGroup.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/ui/src/Radio/RadioGroup.tsx b/packages/ui/src/Radio/RadioGroup.tsx index 2b8eb47..53a1dfd 100644 --- a/packages/ui/src/Radio/RadioGroup.tsx +++ b/packages/ui/src/Radio/RadioGroup.tsx @@ -15,6 +15,19 @@ export const RadioGroupContext = createContext(nu export const useRadioGroup = () => { const context = useContext(RadioGroupContext); if (!context) { + // During SSR/prerendering, context might not be available yet + // Return default values to prevent build errors + if (typeof window === 'undefined') { + return { + name: '', + value: undefined, + onChange: () => {}, + state: 'default' as const, + size: 'md' as const, + disabled: false, + }; + } + // In browser, this is a real error throw new Error('Radio must be used within a RadioGroup'); } return context;