T
TanStack•2w ago
afraid-scarlet

[RC] createServerFn: Getting encoded response in network tab

Hi all, Since the RC update we are getting encoded responses in the network tab.
export const useGetProduct = createServerFn({ method: 'GET' })
.inputValidator((input: {
languageCode: string,
id?: string,
slug?: string
}) => {
if (!validateLanguageCode(input.languageCode)) {
throw new Error('Invalid language code')
}
if (!input.id && !input.slug) {
throw new Error('Either id or slug must be provided')
}
return input
})
.handler(async ({ data }) => {
const { languageCode, id, slug } = data

const productData = await serverRequest<GetProductQuery>(getProductQuery, {
id,
slug
}, languageCode)

if (!productData) {
throw new Error('Product not found')
}

return productData.product
})
export const useGetProduct = createServerFn({ method: 'GET' })
.inputValidator((input: {
languageCode: string,
id?: string,
slug?: string
}) => {
if (!validateLanguageCode(input.languageCode)) {
throw new Error('Invalid language code')
}
if (!input.id && !input.slug) {
throw new Error('Either id or slug must be provided')
}
return input
})
.handler(async ({ data }) => {
const { languageCode, id, slug } = data

const productData = await serverRequest<GetProductQuery>(getProductQuery, {
id,
slug
}, languageCode)

if (!productData) {
throw new Error('Product not found')
}

return productData.product
})
How can we get the raw response back in the network tab? Example of the encoded response we get now:
{
"t": 10,
"i": 0,
"p": {
"k": [
"result",
"error",
"context"
],
"v": [
{
"t": 10,
"i": 1,
"p": {
"k": [
"activeCustomer"
],
"v": [
{
"t": 2,
"s": 0
}
],
"s": 1
},
"o": 0
},
{
"t": 2,
"s": 1
},
{
"t": 10,
"i": 2,
"p": {
"k": [],
"v": [],
"s": 0
},
"o": 0
}
],
"s": 3
},
"o": 0
}
{
"t": 10,
"i": 0,
"p": {
"k": [
"result",
"error",
"context"
],
"v": [
{
"t": 10,
"i": 1,
"p": {
"k": [
"activeCustomer"
],
"v": [
{
"t": 2,
"s": 0
}
],
"s": 1
},
"o": 0
},
{
"t": 2,
"s": 1
},
{
"t": 10,
"i": 2,
"p": {
"k": [],
"v": [],
"s": 0
},
"o": 0
}
],
"s": 3
},
"o": 0
}
Thanks alot!
4 Replies
like-gold
like-gold•2w ago
we use a more powerful serializer for server functions now (same as we did with SSR already ). this has this serialization format. ideally you shouldn't care about that format . why are you though ?
flat-fuchsia
flat-fuchsia•2w ago
I'm getting this error/behaviour as well, I'm not serialising data back, just returning an object and that's the response I'm getting as well
like-gold
like-gold•2w ago
so you are looking at the raw network response?
flat-fuchsia
flat-fuchsia•2w ago
never mind manuel, you're right, replied in the other thread, sorry for bothering 🙂

Did you find this page helpful?