diff --git a/tools/tools.tsx b/tools/tools.tsx index 777171d..e862bf2 100644 --- a/tools/tools.tsx +++ b/tools/tools.tsx @@ -9,11 +9,28 @@ export type SuperJSONProps
= P & {
_superjson?: ReturnType (
gssp: GetServerSideProps ,
exclude: string[] = []
): GetServerSideProps (
...result,
props,
};
- };
+ });
}
export function withSuperJSONInitProps(gip: any, exclude: string[] = []): any {
- return async function withSuperJSON(...args: any[]) {
+ if (isAlreadyPatched(gip)) {
+ return gip;
+ }
+
+ return markAsPatched(async function withSuperJSON(...args: any[]) {
const result = await gip(...args);
const excludedPropValues = exclude.map((propKey) => {
@@ -79,7 +100,7 @@ export function withSuperJSONInitProps(gip: any, exclude: string[] = []): any {
...result,
...props,
};
- };
+ });
}
export function deserializeProps (serializedProps: SuperJSONProps ): P {
@@ -90,13 +111,16 @@ export function deserializeProps (serializedProps: SuperJSONProps ): P {
export function withSuperJSONPage (
Page: React.ComponentType
): React.ComponentType ) {
return (props: P): SuperJSONProps {