Skip to content

Commit 93cc76f

Browse files
committed
Remove workaround for serializing ReadonlyMap
React Router v7.8.2 contains the fix for serializing `ReadonlyMap` and `ReadonlySet` types that someone going by @bjohn465 wrote (see remix-run/react-router#13092). That means this workaround is no longer needed! 🎉
1 parent 3843c20 commit 93cc76f

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

app/routes/day.data.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
type ActionFunctionArgs,
3-
type unstable_SerializesTo as SerializesTo,
4-
type useLoaderData,
5-
} from 'react-router'
1+
import { type ActionFunctionArgs } from 'react-router'
62
import * as v from 'valibot'
73
import { parseFormData } from '#app/form-data.ts'
84
import { Intents, intentSchema } from '#app/intents.ts'
@@ -19,7 +15,7 @@ export function loader() {
1915
'Invalid game state for "day" loader',
2016
)
2117
return {
22-
newsItems: toSerializableReadonlyMap(gameState.newsItems),
18+
newsItems: gameState.newsItems,
2319
paper: dehydratePaper(gameState.paper),
2420
}
2521
}
@@ -70,26 +66,3 @@ const DayActionFormDataSchema = v.variant('intent', [
7066
id: NewsItemIdSchema,
7167
}),
7268
])
73-
74-
/**
75-
* A workaround for https://github.com/remix-run/react-router/issues/13092
76-
* that casts a `ReadonlyMap` to a `SerializesTo<ReadonlyMap>`
77-
* so the map's type serializes correctly when the route loader data is used
78-
* via `useLoaderData`.
79-
* @param readonlyMap The `ReadonlyMap` to cast
80-
* @returns The `ReadonlyMap` as a `SerializesTo<ReadonlyMap>`
81-
*/
82-
function toSerializableReadonlyMap<T>(
83-
readonlyMap: SerializableReadonlyMap<T>,
84-
): SerializesTo<T> {
85-
return readonlyMap as unknown as SerializesTo<T>
86-
}
87-
88-
type SerializableReadonlyMap<T> =
89-
// Get the types of the keys and values
90-
T extends ReadonlyMap<infer K, infer V>
91-
? // Ensure `T` as a `Map` serializes
92-
ReturnType<typeof useLoaderData<() => Map<K, V>>> extends Map<K, V>
93-
? T
94-
: never
95-
: never

0 commit comments

Comments
 (0)