Skip to content

Conversation

@PaulyBearCoding
Copy link

@PaulyBearCoding PaulyBearCoding commented Oct 29, 2025

Summary

Adds comprehensive documentation explaining server function serialization requirements when using Supabase with TanStack Start.

Problem

The Supabase example works correctly but lacks documentation explaining why only primitive values are returned from the fetchUser server function. This causes confusion for developers who want to add more user fields.

Changes

1. New README.md (245 lines)

  • Setup instructions
  • Server Function Serialization section explaining requirements
  • Table showing what's serializable vs not
  • Common errors and solutions
  • Troubleshooting guide
  • Project structure overview

2. Enhanced __root.tsx

  • 40+ line JSDoc comment explaining serialization constraints
  • Examples of correct vs incorrect patterns
  • Better error handling (logs errors instead of suppressing)
  • Commented examples for adding more user fields

What's Serializable?

Type Serializable? Example
String ✅ Yes "hello"
Number ✅ Yes 42
Boolean ✅ Yes true
null ✅ Yes null
Plain Object ✅ Yes { name: "Alice" }
Array ✅ Yes [1, 2, 3]
Function ❌ No Cannot serialize
Date Object ❌ No Convert to ISO string

Testing

  • ✅ Verified with real Supabase credentials
  • ✅ 21+ comprehensive tests run
  • ✅ No hydration errors
  • ✅ No serialization errors
  • ✅ TypeScript compiles cleanly
  • ✅ Code pattern is correct

Fixes

Fixes #3831

Additional Context

The existing code is functionally correct - it already returns only the email field (a primitive). This PR adds the missing documentation that explains:

  1. Why only primitive values are returned
  2. What Supabase user objects contain (non-serializable data)
  3. How to safely add more fields
  4. Common errors and solutions

This helps developers understand the pattern and avoid mistakes when extending the example.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Summary by CodeRabbit

  • Documentation

    • Added a comprehensive README for the TanStack Start + Supabase Basic example covering setup, environment values, dependencies, dev workflow, serialization guidance with a type reference, project structure, auth flow, protected routes, troubleshooting, and deployment notes.
  • Bug Fixes

    • Improved server-side error handling and ensured returned data follow serializable shapes to prevent runtime and serialization issues.

Add comprehensive documentation explaining server function serialization
requirements when using Supabase with TanStack Start.

Changes:
- Add README.md with setup guide and serialization best practices
- Add 40+ line JSDoc comment in __root.tsx explaining serialization constraints
- Improve error handling (log errors instead of suppressing with _error)
- Add inline examples showing correct vs incorrect patterns
- Add commented examples for safely adding more user fields

Fixes TanStack#3831

The code in the Supabase example is functionally correct, but lacked
documentation explaining the serialization requirements for server functions.
This caused confusion for developers who wanted to return additional user
fields from Supabase.

This PR helps developers understand:
- Why only primitive values can be returned from server functions
- What Supabase user objects contain (non-serializable data)
- How to safely add more fields
- Common errors and their solutions

Testing:
- Verified with real Supabase credentials
- Confirmed no hydration errors exist
- Confirmed no serialization errors in current implementation
- Code pattern is correct, documentation was missing

🤖 Generated with Claude Code
Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Walkthrough

Adds a README for the TanStack Start + Supabase Basic example and updates the root route to enforce server-function serialization, narrow returned user data to primitives, and add explicit error handling in the fetchUser server function.

Changes

Cohort / File(s) Summary
Documentation
examples/react/start-supabase-basic/README.md
New README documenting setup (Supabase project, .env, dependencies, dev server), server function serialization rules (allowed types, examples), common errors and fixes, project structure, how the example works, troubleshooting, and deployment notes.
Route: serialization & error handling
examples/react/start-supabase-basic/src/routes/__root.tsx
Adds a serialization guidance comment block, updates fetchUser to log and return null on error, and returns a narrowed, primitive-only user shape to ensure server function results are serializable; preserves prior routing and early-return logic.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Route as __root.tsx
  participant ServerClient as getSupabaseServerClient
  participant Supabase as Supabase API

  Client->>Route: Request page / load
  Route->>ServerClient: getSupabaseServerClient() (no await required)
  ServerClient->>Supabase: check session / fetch auth data
  Supabase-->>ServerClient: returns session & user (may include non-serializable fields)
  ServerClient->>Route: raw data.user
  Note right of Route `#DDEBF7`: fetchUser filters to primitives\nreturns serializable object or null on error
  Route-->>Client: serialized user object or null
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify components/routes accept the narrowed user shape and update usages if they relied on non-primitive fields.
  • Confirm that logging-and-null approach aligns with app error-recovery expectations.
  • Validate README's serialization table and examples are accurate.

Suggested labels

documentation

Suggested reviewers

  • schiller-manuel
  • chorobin

Poem

🐰 A tiny README, tidy and light,
Server returns trimmed to keep things right.
Errors caught softly, payloads now clear,
Hydration gremlins hopping far from here.
✨ Hoppity code, the example's bright!

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding serialization documentation to the Supabase example. It directly relates to the primary objective of the PR.
Linked Issues check ✅ Passed All coding objectives from issue #3831 are addressed: serialization constraints documented, non-serializable data handling fixed, error handling improved, and hydration errors resolved.
Out of Scope Changes check ✅ Passed All changes directly address the linked issue #3831. README documentation and code enhancements focus on serialization requirements and Supabase Auth integration without extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 939c66a and 319f9bb.

📒 Files selected for processing (1)
  • examples/react/start-supabase-basic/README.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/react/start-supabase-basic/README.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
examples/react/start-supabase-basic/README.md (2)

7-12: Fix markdown linting issues in setup section.

The bare URL and code block without language specifier trigger markdown linting warnings. While these don't affect functionality, addressing them improves documentation consistency.

Apply this diff:

-1. Create a Supabase project at https://supabase.com
+1. Create a Supabase project at [Supabase](https://supabase.com)
 2. Copy `.env` and fill in your Supabase credentials:
-   ```
+   ```bash
    SUPABASE_URL=your-project-url
    SUPABASE_ANON_KEY=your-anon-key
    ```

100-100: Add language specifier to project structure code block.

Apply this diff:

-```
+```text
 src/
 ├── routes/
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec3881 and 761e783.

📒 Files selected for processing (2)
  • examples/react/start-supabase-basic/README.md (1 hunks)
  • examples/react/start-supabase-basic/src/routes/__root.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
examples/{react,solid}/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep example applications under examples/react/ and examples/solid/

Files:

  • examples/react/start-supabase-basic/README.md
  • examples/react/start-supabase-basic/src/routes/__root.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • examples/react/start-supabase-basic/src/routes/__root.tsx
**/src/routes/**

📄 CodeRabbit inference engine (AGENTS.md)

Place file-based routes under src/routes/ directories

Files:

  • examples/react/start-supabase-basic/src/routes/__root.tsx
🧬 Code graph analysis (1)
examples/react/start-supabase-basic/src/routes/__root.tsx (1)
examples/react/start-supabase-basic/src/utils/supabase.ts (1)
  • getSupabaseServerClient (4-24)
🪛 markdownlint-cli2 (0.18.1)
examples/react/start-supabase-basic/README.md

7-7: Bare URL used

(MD034, no-bare-urls)


9-9: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


100-100: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (7)
examples/react/start-supabase-basic/README.md (4)

16-60: Excellent documentation of serialization requirements.

This section clearly explains the serialization constraints and provides practical examples. The distinction between serializable primitives and non-serializable types (functions, class instances, Date objects) is accurate and well-presented.


61-97: LGTM! Practical troubleshooting guide.

The common errors section addresses real issues developers will encounter. The code examples show clear before/after patterns, and the ?? null operator usage is idiomatic for handling undefined values.


120-169: LGTM! Implementation examples are accurate.

The "How It Works" section provides clear explanations with code examples that match the actual implementation. The emphasis on serialization in the fetchUser example (line 134) reinforces the key concept introduced earlier.


170-196: LGTM! Helpful resources and troubleshooting tips.

The documentation links and troubleshooting section provide good next steps for developers. The deployment platform compatibility list is accurate for TanStack Start applications.

examples/react/start-supabase-basic/src/routes/__root.tsx (3)

18-53: Excellent inline documentation for serialization requirements.

This comprehensive JSDoc comment provides clear guidance right where developers need it. The examples of wrong vs correct patterns, along with the serializable types reference, will help prevent the common serialization errors this PR aims to address.


54-62: LGTM! Improved error handling with explicit logging.

The change from _error (intentionally ignored) to error with explicit console.error logging is a debugging improvement. The contextual prefix [fetchUser] makes error source identification easier during troubleshooting.


64-77: LGTM! Serialization implementation is correct and well-documented.

The return statement correctly extracts only primitive fields from the Supabase user object. The commented examples provide clear guidance for safely adding additional fields, including the ?? null pattern for handling potentially undefined values from user_metadata.

@nx-cloud
Copy link

nx-cloud bot commented Nov 11, 2025

View your CI Pipeline Execution ↗ for commit 939c66a

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ⛔ Cancelled 17s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-11 15:27:59 UTC

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
examples/react/start-supabase-basic/README.md (2)

7-7: Wrap bare URLs in markdown link syntax.

Lines 7 and 182 contain bare URLs that should be wrapped in markdown link syntax for consistency and better rendering.

Apply this diff to fix the bare URLs:

-1. Create a Supabase project at https://supabase.com
+1. Create a Supabase project at [https://supabase.com](https://supabase.com)
-  - [Supabase Auth Documentation](https://supabase.com/docs/guides/auth)
+  - [Supabase Auth Documentation](https://supabase.com/docs/guides/auth)

Also applies to: 182-182


9-9: Add language specifications to fenced code blocks.

Lines 9 and 103 have fenced code blocks without language identifiers. Specify bash for the .env block and text or plaintext for the file structure.

Apply these diffs:

-   ```
+   ```bash
    SUPABASE_URL=your-project-url
    SUPABASE_ANON_KEY=your-anon-key
-   ```
+   ```
-\`\`\`
+\`\`\`plaintext
 src/
 ├── routes/
 │   ├── __root.tsx          # Root layout with user fetching
@@ -117,7 +117,7 @@ src/
 │   └── posts.ts
 └── styles/
     └── app.css
-\`\`\`
+\`\`\`

Also applies to: 103-103

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 761e783 and 939c66a.

📒 Files selected for processing (1)
  • examples/react/start-supabase-basic/README.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
examples/{react,solid}/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep example applications under examples/react/ and examples/solid/

Files:

  • examples/react/start-supabase-basic/README.md
🪛 markdownlint-cli2 (0.18.1)
examples/react/start-supabase-basic/README.md

7-7: Bare URL used

(MD034, no-bare-urls)


9-9: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


103-103: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (1)
examples/react/start-supabase-basic/README.md (1)

1-209: Comprehensive and well-structured documentation.

The README effectively documents the serialization constraints and provides clear, practical guidance. The "Server Function Serialization" section (lines 16–60) directly addresses the core issue #3831 with concrete examples, a helpful reference table, and common error solutions. The "How It Works" section ties the documentation to the actual code patterns. Project structure and troubleshooting sections enhance clarity for new users.

Minor markdown linting issues aside (bare URLs and missing code block language specs), the content quality and completeness are excellent for onboarding developers using TanStack Start with Supabase auth.

- Wrap bare URL in markdown link syntax
- Add language specifiers to code blocks (bash, text)
- Address CodeRabbitAI review feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tanstack Start Supabase Auth documentation is broken

1 participant