Skip to content

Commit ab8b368

Browse files
committed
fix: pass superjson instance to custom register
1 parent 8e5520c commit ab8b368

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/core/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export function getFlytrapStorage(flytrapStorage?: FlytrapStorage) {
304304
}
305305

306306
function isSerializable(input: any) {
307-
superJsonRegisterCustom()
307+
superJsonRegisterCustom(SuperJSON)
308308
const { error } = tryCatchSync(() => SuperJSON.stringify(input))
309309
return error === null
310310
}

src/core/stringify.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ import {
88
FLYTRAP_RESPONSE
99
} from './constants'
1010

11-
export function superJsonRegisterCustom() {
11+
export function superJsonRegisterCustom(superJsonInstance: typeof SuperJSON) {
1212
// Fetch API classes
13-
SuperJSON.registerCustom<any, string>(
13+
superJsonInstance.registerCustom<any, string>(
1414
{
1515
isApplicable: (v): v is Headers => v instanceof Headers,
1616
serialize: () => FLYTRAP_HEADERS,
1717
deserialize: () => FLYTRAP_HEADERS
1818
},
1919
'Headers'
2020
)
21-
SuperJSON.registerCustom<any, string>(
21+
superJsonInstance.registerCustom<any, string>(
2222
{
2323
isApplicable: (v): v is Response => v instanceof Response,
2424
serialize: () => FLYTRAP_RESPONSE,
2525
deserialize: () => FLYTRAP_RESPONSE
2626
},
2727
'Response'
2828
)
29-
SuperJSON.registerCustom<any, string>(
29+
superJsonInstance.registerCustom<any, string>(
3030
{
3131
isApplicable: (v): v is Request => v instanceof Request,
3232
serialize: () => FLYTRAP_REQUEST,
@@ -36,7 +36,7 @@ export function superJsonRegisterCustom() {
3636
)
3737

3838
// handle functions
39-
SuperJSON.registerCustom<any, string>(
39+
superJsonInstance.registerCustom<any, string>(
4040
{
4141
isApplicable: (v): v is Function => typeof v === 'function',
4242
serialize: () => FLYTRAP_FUNCTION,
@@ -46,7 +46,7 @@ export function superJsonRegisterCustom() {
4646
)
4747

4848
// handle DOM events
49-
SuperJSON.registerCustom<any, string>(
49+
superJsonInstance.registerCustom<any, string>(
5050
{
5151
isApplicable: (v): v is Event => {
5252
return typeof window !== 'undefined' ? v instanceof window.Event : false
@@ -64,7 +64,7 @@ export function superJsonRegisterCustom() {
6464
* @returns stringified object with cyclical dependencies removed
6565
*/
6666
export function stringify(obj: any): string {
67-
superJsonRegisterCustom()
67+
superJsonRegisterCustom(SuperJSON)
6868

6969
const serialized = SuperJSON.serialize(obj)
7070
if (serialized.meta?.referentialEqualities) {
@@ -87,6 +87,6 @@ export function stringify(obj: any): string {
8787
}
8888

8989
export function parse<T = unknown>(stringified: string): T {
90-
superJsonRegisterCustom()
90+
superJsonRegisterCustom(SuperJSON)
9191
return SuperJSON.parse<T>(stringified)
9292
}

0 commit comments

Comments
 (0)