Shared SSR/SSG hooks are not transformed
Opened this issue · 4 comments
alii commented
When writing getStaticProps
outside of a page file, the superjson code is never injected. For example:
// props.ts
export const getStaticProps: GetStaticProps<Props> = async ctx => {
// ...
}
// pages/page.tsx
export {getStaticProps} from '../props';
export default function Page() {
// ...
}
Skn0tt commented
Hi @alii! Would you be interested in contributing a fix for this? You should be able to add a test case for this in here: https://github.com/blitz-js/babel-plugin-superjson-next/tree/main/test
alii commented
Can certainly have a go, but I've never written a babel plugin before. Learning time!
Skn0tt commented
love it! feel free to shoot me a question if you're stuck :)
apieceofbart commented
For a quick hack you can just manually add superjson like so (until the PR is merged):
import { getServerSideProps } from "./getServerSideProps";
import { withSuperJSONPage as _withSuperJSONPage } from "babel-plugin-superjson-next/tools";
import { withSuperJSONProps as _withSuperJSONProps } from "babel-plugin-superjson-next/tools";
const getServerSidePropsWithSuperJSONProps =
_withSuperJSONProps(getServerSideProps);
function Page() {
...
export { getServerSidePropsWithSuperJSONProps as getServerSideProps };
export default _withSuperJSONPage(Page);