Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWC should transform pageProps from _app.tsx #72

Open
1 task done
pixelpax opened this issue Mar 10, 2023 · 0 comments
Open
1 task done

SWC should transform pageProps from _app.tsx #72

pixelpax opened this issue Mar 10, 2023 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@pixelpax
Copy link

pixelpax commented Mar 10, 2023

Verify Next.js canary release

  • 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, 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.

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

     return ( <QueryClientProvider client={rssQueryClient}>
        <Hydrate state={pageProps.dehydratedState}>
              <Component {...pageProps} />
        </Hydrate>
      </QueryClientProvider>);
}

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

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

Additional context

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

  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.

@pixelpax pixelpax added the bug Something isn't working label Mar 10, 2023
@orionmiz orionmiz added this to the Planned milestone Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants