blitz-js / blitz-js/next-superjson-plugin

Support of non-default object types

Open
#80 5 comments 18 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
216
Forks
13
PR merge metrics
No merged PRs in 30d

Description

### Verify Next.js canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Describe the bug

Non-default object types aren't picked up and you get the following error:

- error node_modules/.pnpm/superjson@1.12.2/node_modules/superjson/dist/transformer.js (184:0) @ Object.eval [as untransform]
- error Error: Trying to deserialize unknown custom value
at Array.forEach ()
null

I followed the suggested custom recipe format and inject it near the root of my app:

```
import SuperJSON from 'superjson'

export function registerCustomTypes() {
// Register Decimal as a custom type
// Ref: https://github.com/blitz-js/superjson/pull/159/files
SuperJSON.registerCustom(
{
isApplicable: (v): v is Decimal => Decimal.isDecimal(v),
serialize: (v) => v.toJSON(),
deserialize: (v) => new Decimal(v),
},
'Decimal',
)
}
```

### Expected behavior

The `next-superjson-plugin` should function the same as `superjson` when called directly.

### Reproduction link

_No response_

### Version

^0.5.7

### Config

```javascript
export default {
reactStrictMode: true,
swcMinify: true,
images: {
domains: [],
},
experimental: {
appDir: true,
serverComponentsExternalPackages: ['@prisma/client'],
swcPlugins: [['next-superjson-plugin', {}]],
},
}
```

### Additional context

I was able to follow the example from [Superjson](https://github.com/blitz-js/superjson#recipes) on adding custom types and can use superjson directly to serialize and then parse it back to the original object, but when using `data-superjson` it doesn't work and I get the error above.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the reported setup with the next-superjson-plugin configuration, the SuperJSON custom Decimal registration, and the data-superjson path. Compare that behavior with direct SuperJSON serialization and deserialization; done means the custom object type is recognized and deserialized successfully through the Next.js plugin.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, rust
Domain
tooling, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.