How to fix CORS errors: a practical guide
What CORS errors actually mean, why they happen, and how to fix them correctly on the server, including preflight requests, credentials and common mistakes.
Why React hydration mismatches happen in server-rendered apps, how to read the error, and reliable fixes for dates, browser-only code, invalid HTML and extensions.
A hydration error means the HTML React rendered on the server doesn't match what it renders in the browser during hydration. Common causes are values that differ between server and client, such as dates, random numbers or browser-only data, invalid HTML nesting, and browser extensions changing the page. Make the first client render match the server, move browser-only logic into effects or client-only components and fix invalid markup.
Server-side rendering makes React apps faster and more search-friendly: the server sends ready-made HTML, then React "hydrates" it in the browser, attaching event handlers and taking over. Hydration expects the browser render to match the server HTML. When it doesn't, React reports a hydration error and may re-render parts of the page.
Modern React and frameworks like Next.js show which element and text differ between server and client. Look for:
Rendering the current time or formatting dates with the user's locale gives different results on the server and in the browser.
Fix: render a stable value on the server, such as an ISO date, then update to a local format after mount in an effect, or render times only on the client.
Math.random or generated IDs differ between renders.
Fix: use React's useId hook for IDs, and generate random values after mount if needed.
Code that reads window, localStorage, screen size or user agent during render runs differently on the server, where those don't exist.
Fix: read browser-only data in useEffect, after hydration, or render those parts only on the client using your framework's client-only options.
Showing different content for logged-in users, themes or screen sizes based on browser data creates mismatches.
Fix: render a consistent placeholder first, then update after mount; or determine the state on the server using cookies or headers.
Browsers automatically correct invalid HTML, such as a div inside a p, or nested links. The corrected DOM no longer matches React's expectations.
Fix: use valid nesting; check component output for block elements inside paragraphs and interactive elements inside each other.
Extensions like translators, password managers and ad blockers can modify the page before React hydrates.
Fix: test in a private window without extensions. If only extensions cause it, your code may be fine, though some attributes on the html or body elements may be safely ignored.
Server and client fetching different data, or caching differently, creates mismatches.
Fix: pass server-fetched data to the client rather than refetching during the first render.
React allows suppressing hydration warnings for specific elements, such as timestamps. Use this sparingly and only when a mismatch is expected and harmless. Fix underlying causes wherever possible.
Hydration mismatches can cause flickering, lost interactivity, slower performance and inconsistent content. Fixing them improves user experience and reliability.
Client-side effects that aren't cleaned up can cause memory leaks; see our guide to fixing JavaScript memory leaks. API calls failing in the browser may be CORS problems; see our guide to fixing CORS errors.
Analytics, chat widgets and A/B testing tools sometimes change the DOM before React hydrates. Load them after hydration or in ways that don't modify server-rendered elements React controls.
Framework updates often improve hydration error messages and handling. Keeping React and your framework reasonably current makes debugging easier.
Our web app development team builds and debugs server-rendered React applications. Our web development team optimises rendering strategies for speed and SEO, and our app development service shares reliable patterns across web and mobile.
The process where React attaches event handlers and takes over server-rendered HTML in the browser.
The server and browser often have different time zones and locales, so formatted dates differ.
Usually not. Fix the mismatch instead, so you keep the speed and SEO benefits of server rendering.
This guide is general information, not legal, tax or financial advice, and details such as prices, features and rules can change. Product and company names mentioned are trademarks of their respective owners and are used only to identify those products; UK Technology Hub is not affiliated with or endorsed by them.
Tell us about your project and get a free, fixed quote.
Get a free quoteWhat CORS errors actually mean, why they happen, and how to fix them correctly on the server, including preflight requests, credentials and common mistakes.
What memory leaks look like in web apps, the most common causes, how to find them with browser developer tools, and patterns that prevent them.
A calm, step-by-step guide to diagnosing and fixing a blank white WordPress page, from recovery mode and debug logs to plugins, themes and memory limits.