feat: add Next.js SSR compatibility support#111
Open
lucky7323 wants to merge 1 commit intoMDTechLabs:mainfrom
Open
feat: add Next.js SSR compatibility support#111lucky7323 wants to merge 1 commit intoMDTechLabs:mainfrom
lucky7323 wants to merge 1 commit intoMDTechLabs:mainfrom
Conversation
- Add SSR-safe utilities (env detection, safe storage, browser guards) - Implement useIsClient and useIsomorphicLayoutEffect hooks - Add ClientOnly component for safe client-side rendering - Create @bridgewise/next-adapter package with dynamic imports - Update README with SSR usage examples and migration guide - Ensure 'use client' directives are preserved for React 18+ compatibility Resolves MDTechLabs#58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BridgeWise SDK React components and hooks cause runtime errors and hydration mismatches when used in Next.js SSR environments due to direct access to browser APIs (
window,document,localStorage) during server-side rendering.Solution
This PR introduces comprehensive SSR compatibility for BridgeWise components while maintaining backward compatibility with existing client-side usage.
Key Features
🛠️ SSR-Safe Utilities
isServer/isClientenvironment detectionsafeStorageAPI with fallback support for localStorage operationscreateBrowserGuardfor explicit server access error handling⚛️ React SSR Hooks
useIsClient- prevents hydration mismatches by detecting client-side hydration completionuseIsomorphicLayoutEffect- eliminates SSR warnings fromuseLayoutEffect🧩 SSR Components
ClientOnlycomponent with fallback support for server-side rendering📦 Next.js Adapter Package
@bridgewise/next-adapter- dedicated package withnext/dynamicwrappersBridgeStatusDynamic,BridgeCompareDynamic,ClientOnlyDynamicUsage Examples
Basic SSR-safe usage:
Next.js dynamic imports:
Compatibility
Technical Implementation
@bridgewise/ui-componentsThis implementation ensures BridgeWise components work seamlessly in modern SSR frameworks while preserving full backward compatibility.
Fixes #58