superjson serializes the payload into two subkeys json and meta. if json key is not present in your payload, it can not deserialize it and returns undefined. just create a custom transformer to account for that.
import SuperJSON, { type SuperJSONResult } from "superjson";
export const transformer = {
input: {
/**
* This function runs **on the client** before sending the data to the server.
*/
serialize: SuperJSON.serialize,
/**
* This function runs **on the server** to transform the data before it is passed to the resolver
*/
deserialize: (obj: SuperJSONResult) => {
if ("json" in obj) {
return SuperJSON.deserialize(obj);
} else {
return SuperJSON.deserialize({ json: obj });
}
},
},
output: {
/**
* This function runs **on the server** before sending the data to the client.
*/
serialize: SuperJSON.serialize,
/**
* This function runs **only on the client** to transform the data sent from the server.
*/
deserialize: SuperJSON.deserialize,
},
};
import SuperJSON, { type SuperJSONResult } from "superjson";
export const transformer = {
input: {
/**
* This function runs **on the client** before sending the data to the server.
*/
serialize: SuperJSON.serialize,
/**
* This function runs **on the server** to transform the data before it is passed to the resolver
*/
deserialize: (obj: SuperJSONResult) => {
if ("json" in obj) {
return SuperJSON.deserialize(obj);
} else {
return SuperJSON.deserialize({ json: obj });
}
},
},
output: {
/**
* This function runs **on the server** before sending the data to the client.
*/
serialize: SuperJSON.serialize,
/**
* This function runs **only on the client** to transform the data sent from the server.