blitz-js / babel-plugin-superjson-next

Automatically transform your Next.js Pages to use SuperJSON
MIT License
124 stars 15 forks source link

Issue when using an export list for `getServerSideProps` #134

Closed florian-milky closed 1 year ago

florian-milky commented 1 year ago

Hi! I wanna report a small bug kind of similar to https://github.com/blitz-js/babel-plugin-superjson-next/issues/100

This did not work 🔴

import {
  getServerSideProps,
  PreviewPage,
} from '../../../common-components/contentful-elements/pages/preview';

export { getServerSideProps };

export default PreviewPage;

I changed to

import {
  getServerSideProps as getPreviewServerSideProps,
  PreviewPage,
} from '../../../common-components/contentful-elements/pages/preview';

export const getServerSideProps = getPreviewServerSideProps;

export default PreviewPage;

and it worked ✅

Skn0tt commented 1 year ago

Oh interesting! Yeah the babel transpilation logic is finicky 😅 The way I'd go about fixing this is to add a new testcase in https://github.com/blitz-js/babel-plugin-superjson-next/tree/main/test/pages, and then step through https://github.com/blitz-js/babel-plugin-superjson-next/blob/main/src/index.ts with a debugger to fix it. Would you be interested in contributing a fix for this? I can also do it, just let me know.

florian-milky commented 1 year ago

@Skn0tt I'd be interested but I don't think I'll have the time. Sorry!

Skn0tt commented 1 year ago

opened a draft PR. not sure when I'll have some spare time to find a solution, but i'll get to it! in the meantime, i'm happy you found a workaround already.