Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Oct 6, 2025

Summary by CodeRabbit

  • New Features

    • Added public typings to mark custom objects as serializable (TsrSerializable), expanding type-checked serialization support without changing runtime behavior.
    • Extended default serializable recognition to accept types annotated as serializable.
  • Tests

    • Added type-level tests validating serialization rules and error cases.
    • Updated tests to ensure server-related utilities accept custom serializable types.

@nx-cloud
Copy link

nx-cloud bot commented Oct 6, 2025

View your CI Pipeline Execution ↗ for commit 7f454ed

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

☁️ Nx Cloud last updated this comment at 2025-10-06 20:09:41 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Walkthrough

Adds a serializable marker symbol and type (TSR_SERIALIZABLE, TsrSerializable), exports them from router-core public API, extends DefaultSerializable typing, removes a commented module augmentation, and adds TypeScript declaration tests validating serializer typings and interop.

Changes

Cohort / File(s) Summary
Public API exports
packages/router-core/src/index.ts
Exported TSR_SERIALIZABLE and TsrSerializable from ssr/serializer/transformer.
Serializer transformer typing
packages/router-core/src/ssr/serializer/transformer.ts
Added exported constant/type TSR_SERIALIZABLE, added exported type TsrSerializable, and included TsrSerializable in DefaultSerializable.
SSR server cleanup
packages/router-core/src/ssr/server.ts
Removed a commented module augmentation block; no runtime or API signature changes.
Type tests: serializer
packages/router-core/tests/serializer.test-d.ts
New declaration tests validating default serializable types, non-serializable function error, and acceptance of types marked with TSR_SERIALIZABLE.
Type tests: start-client-core
packages/start-client-core/src/tests/createServerFn.test-d.ts
Imported TsrSerializable and added a test asserting createServerFn accepts a TsrSerializable-augmented nested type.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • chorobin

Poem

I twitch my whiskers at a shiny new sign,
A symbol that says “serializable? Fine!”
Types all aligned, with tests in tow,
I thump my paw—now off we go.
Hop, hop, ship it—TSR divine! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “fix: add TsrSerializable” succinctly captures the primary change in this pull request by indicating the addition of the TsrSerializable export, which aligns directly with the modifications to the public API. It is clear, concise, and focused on the main development effort without extraneous detail. The prefix “fix:” follows the existing commit convention and does not detract from readability or accuracy.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tsr-serializable

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 6, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5387

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5387

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5387

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5387

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5387

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5387

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5387

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5387

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5387

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5387

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5387

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5387

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5387

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5387

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5387

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5387

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5387

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5387

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5387

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5387

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5387

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5387

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5387

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5387

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5387

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5387

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5387

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5387

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5387

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5387

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5387

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5387

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5387

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5387

commit: 7f454ed

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 (1)
packages/router-core/src/ssr/serializer/transformer.ts (1)

12-13: LGTM! Solid escape hatch implementation.

The use of Symbol.for('TSR_SERIALIZABLE') ensures a global symbol that works across module boundaries. The TsrSerializable type provides a clean type-level marker for users to opt out of serialization validation when needed.

Consider adding JSDoc to clarify the purpose and usage:

+/**
+ * Symbol marker for types that should be treated as serializable.
+ * Use this as an escape hatch when you have types that aren't naturally
+ * serializable but you know are safe in your specific context.
+ * 
+ * @example
+ * type MyCustomType = MyClass & TsrSerializable
+ */
 export const TSR_SERIALIZABLE = Symbol.for('TSR_SERIALIZABLE')
+
+/**
+ * Type marker to indicate a type is serializable.
+ * Intersection with this type bypasses serialization validation.
+ */
 export type TsrSerializable = { [TSR_SERIALIZABLE]: true }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8052ce and a2dfc99.

📒 Files selected for processing (5)
  • packages/router-core/src/index.ts (1 hunks)
  • packages/router-core/src/ssr/serializer/transformer.ts (2 hunks)
  • packages/router-core/src/ssr/server.ts (0 hunks)
  • packages/router-core/tests/serializer.test-d.ts (1 hunks)
  • packages/start-client-core/src/tests/createServerFn.test-d.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/router-core/src/ssr/server.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

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

Files:

  • packages/router-core/src/ssr/serializer/transformer.ts
  • packages/router-core/src/index.ts
  • packages/start-client-core/src/tests/createServerFn.test-d.ts
  • packages/router-core/tests/serializer.test-d.ts
packages/router-core/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep framework-agnostic core router logic in packages/router-core/

Files:

  • packages/router-core/src/ssr/serializer/transformer.ts
  • packages/router-core/src/index.ts
  • packages/router-core/tests/serializer.test-d.ts
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/start-client-core/src/tests/createServerFn.test-d.ts
🧬 Code graph analysis (3)
packages/router-core/src/ssr/serializer/transformer.ts (1)
packages/router-core/src/index.ts (2)
  • TSR_SERIALIZABLE (426-426)
  • TsrSerializable (427-427)
packages/start-client-core/src/tests/createServerFn.test-d.ts (2)
packages/router-core/src/ssr/serializer/transformer.ts (1)
  • TsrSerializable (13-13)
packages/start-client-core/src/createServerFn.ts (1)
  • createServerFn (49-168)
packages/router-core/tests/serializer.test-d.ts (1)
packages/router-core/src/ssr/serializer/transformer.ts (4)
  • ValidateSerializableResult (229-238)
  • Serializable (27-27)
  • ValidateSerializable (66-85)
  • TSR_SERIALIZABLE (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
🔇 Additional comments (5)
packages/router-core/src/index.ts (1)

426-427: LGTM! Clean public API extension.

The new exports follow the existing patterns and correctly expose the serialization escape hatch mechanism.

packages/start-client-core/src/tests/createServerFn.test-d.ts (2)

5-10: LGTM! Import additions are clean.

The new TsrSerializable import is correctly added alongside existing types from @tanstack/router-core.


647-657: LGTM! Test validates the escape hatch correctly.

This test effectively validates that TsrSerializable allows marking otherwise non-serializable types (containing functions) as serializable. The type assertion pattern is appropriate for this type-level marker.

packages/router-core/tests/serializer.test-d.ts (1)

1-74: LGTM! Comprehensive type-level test coverage.

This test suite effectively validates:

  • Default serializable types are correctly recognized (primitives, Date, bigint)
  • Non-serializable types (functions) produce the expected error signature
  • The TsrSerializable escape hatch allows marking custom types as serializable

The tests provide strong compile-time guarantees for the serialization type system.

packages/router-core/src/ssr/serializer/transformer.ts (1)

22-22: LGTM! Correct integration into the type system.

Adding TsrSerializable to DefaultSerializable ensures types marked with the symbol pass through ValidateSerializable checks, which is the intended behavior for this escape hatch mechanism.

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 (1)
packages/router-core/tests/serializer.test-d.ts (1)

11-11: Remove the unused $name placeholder from the describe block.

The $name in the describe block name appears to be an unused placeholder. Consider simplifying to just 'Default types are serializable'.

Apply this diff:

-  describe('Default types are serializable: $name', () => {
+  describe('Default types are serializable', () => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 712b0a9 and 7f454ed.

📒 Files selected for processing (1)
  • packages/router-core/tests/serializer.test-d.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

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

Files:

  • packages/router-core/tests/serializer.test-d.ts
packages/router-core/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep framework-agnostic core router logic in packages/router-core/

Files:

  • packages/router-core/tests/serializer.test-d.ts
🧬 Code graph analysis (1)
packages/router-core/tests/serializer.test-d.ts (1)
packages/router-core/src/ssr/serializer/transformer.ts (4)
  • ValidateSerializableResult (231-240)
  • Serializable (29-29)
  • ValidateSerializable (68-87)
  • TsrSerializable (15-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (3)
packages/router-core/tests/serializer.test-d.ts (3)

1-8: LGTM!

The imports are correctly structured and pull in the necessary types from the serializer transformer module.


61-66: LGTM!

The test correctly validates that function types produce the expected compile-time error message.


68-73: LGTM! Critical test for the new TsrSerializable functionality.

This test validates the core feature of this PR: the TsrSerializable marker allows custom types to bypass normal validation rules. Even though MyCustomType contains a function property, it's accepted because it extends TsrSerializable.

Based on the ValidateSerializable implementation in transformer.ts (lines 67-86), the check for T extends TSerializable occurs before the function check, which makes this behavior correct.

@schiller-manuel schiller-manuel merged commit 020e96b into main Oct 6, 2025
6 checks passed
@schiller-manuel schiller-manuel deleted the tsr-serializable branch October 6, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants