Course contentsShow
← React
Lesson 1596 of 2,39639. Server Components in PracticeFree lesson

Debugging Serialization Errors

React throws clear errors when non-serializable props are passed; use JSON.stringify() to test serializability locally.

Debugging Serialization Errors

What you'll learn: How to identify and fix serialization errors when passing props across the server-client boundary in React.

React's Helpful Error Messages

When you accidentally pass non-serializable data (like functions, class instances, or Symbols) across the server-client boundary, React doesn't fail silently. It throws clear, descriptive errors that tell you exactly what went wrong and where.

These errors typically look like:

Error: Functions cannot be passed from Server to Client Components.
Only serializable data can cross the boundary.

The error message will often include:

  • The component where the error occurred
  • The prop name that caused the problem
  • The type of value that couldn't be serialized

Testing Serializability Locally

Before relying on runtime errors, you can test if something is serializable using JSON.stringify():

const data = {
  user: { name: 'Alice', id: 123 },
  onClick: () => console.log('click'), // Function!
  date: new Date()
};

try {
  JSON.stringify(data);
  console.log('✓ Serializable');
} catch (error) {
  console.log('✗ Not serializable:', error.message);
}

This works because React's serialization mechanism is similar to JSON (though slightly more permissive—it allows undefined, for example). If JSON.stringify() throws an error, React won't be able to serialize it either.

Quick Debugging Workflow

  1. See a serialization error? Read the error message carefully
  2. Locate the problematic prop in your component
  3. Test locally with JSON.stringify() if unsure
  4. Replace with serializable alternatives (e.g., pass data instead of functions, use Server Component children pattern)

Key Takeaway: React provides explicit serialization errors to catch boundary violations early, and you can preemptively test serializability using JSON.stringify() during development.