From e188ecb9ee8709ca8c1525c19ae2dd8e15743085 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Nov 2024 14:58:08 +0100 Subject: [PATCH 1/4] Add `SerializesTo` brand type. --- .changeset/sour-avocados-lick.md | 5 +++++ packages/react-router/lib/types.ts | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/sour-avocados-lick.md diff --git a/.changeset/sour-avocados-lick.md b/.changeset/sour-avocados-lick.md new file mode 100644 index 0000000000..0b59d80873 --- /dev/null +++ b/.changeset/sour-avocados-lick.md @@ -0,0 +1,5 @@ +--- +"react-router": patch +--- + +Add `SerializesTo` brand type. diff --git a/packages/react-router/lib/types.ts b/packages/react-router/lib/types.ts index 1485676882..69eec4470b 100644 --- a/packages/react-router/lib/types.ts +++ b/packages/react-router/lib/types.ts @@ -93,9 +93,22 @@ type ServerDataFunctionArgs = ClientDataFunctionArgs & { context: AppLoadContext; }; +/** + * A brand that can be applied to a type to indicate that it will serialize + * to a specific type when transported to the client from a loader. + * Only use this if you have additional serialization/deserialization logic + * in your application. + */ +export type SerializesTo = { + $__RR_SerializesTo?: [T]; +}; + // prettier-ignore type Serialize = - // First, let type stay as-is if its already serializable... + // First, if type has a `SerializesTo` brand, use that type + T extends SerializesTo ? To : + + // Then, let type stay as-is if its already serializable... T extends Serializable ? T : // ...then don't allow functions to be serialized... From 1300e60fb9089dae88787d25f2975bf7ad884412 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 12 Nov 2024 15:16:45 +0100 Subject: [PATCH 2/4] sign CLA --- contributors.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.yml b/contributors.yml index 6f8d26065c..5b2fe20db2 100644 --- a/contributors.yml +++ b/contributors.yml @@ -216,6 +216,7 @@ - pavsoldatov - pcattori - petersendidit +- phryneas - promet99 - pyitphyoaung - refusado From b383d3c18d0e8708bca65c7b06b5e46673bd06fa Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Wed, 13 Nov 2024 11:03:52 +0100 Subject: [PATCH 3/4] Update .changeset/sour-avocados-lick.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaƫl De Boey --- .changeset/sour-avocados-lick.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/sour-avocados-lick.md b/.changeset/sour-avocados-lick.md index 0b59d80873..45b1572883 100644 --- a/.changeset/sour-avocados-lick.md +++ b/.changeset/sour-avocados-lick.md @@ -1,5 +1,5 @@ --- -"react-router": patch +"react-router": minor --- Add `SerializesTo` brand type. From 938d3d9a8be4e3d1945173f9ed69403027994c0f Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 24 Jan 2025 09:57:23 +0100 Subject: [PATCH 4/4] change `__RR_SerializesTo` to `__ReactRouter_SerializesTo` --- packages/react-router/lib/types/route-module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-router/lib/types/route-module.ts b/packages/react-router/lib/types/route-module.ts index de617ebeb8..1ff6cba63e 100644 --- a/packages/react-router/lib/types/route-module.ts +++ b/packages/react-router/lib/types/route-module.ts @@ -268,5 +268,5 @@ type __tests = [ * in your application. */ export type SerializesTo = { - $__RR_SerializesTo?: [T]; + __ReactRouter_SerializesTo?: [T]; };