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

SWC should transform pageProps from _app.tsx

Open
#72 0 comments 2 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

In order to use patterns like [react-query prefetch](https://tanstack.com/query/v4/docs/react/guides/ssr), the transform must happen in _app.tsx, as well as in the specific pages.

In this and other common patterns, _app.tsx may be passing some pageProps into global providers.

As it is currently, pageProps will be passed into global providers untransformed, leading to difficult to solve bugs.

```jsx
export default function App({ Component, pageProps }: AppProps) {

return (



);
}
```

### Expected behavior

I would expect `pageProps` to be transformed when received by _app.tsx

### Reproduction link

_No response_

### Version

"next-superjson-plugin": "^0.5.6"
"superjson": "^1.12.2",

### Config

```javascript
const nextConfig = {
experimental: {
swcPlugins: [
[
'next-superjson-plugin',
{
excluded: []
}
]
]
},
output: 'standalone'
};
```

### Additional context

An easy workaround for the time being is to do something like

```tsx
const fixedPageProps = useMemo(() => superjson.deserialize({
json: pageProps,
meta: pageProps._superjson
}) as AppProps["pageProps"], [pageProps]);
```
and use `fixedPageProps` where `pageProps` would be inserted normally. Hopefully this is helpful for someone, though I do feel strongly that this should be solved by the SWC as default behavior.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.