diff --git a/example/yarn.lock b/example/yarn.lock index 1909c84..a4e8c46 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -192,6 +192,13 @@ dependencies: "@babel/types" "^7.12.5" +"@babel/helper-module-imports@^7.12.13": + version "7.12.13" + resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.12.13.tgz#ec67e4404f41750463e455cc3203f6a32e93fcb0" + integrity sha512-NGmfvRp9Rqxy0uHSSVP+SRIW1q31a7Ji10cLBcqSDUngGentY4FRiHOFZFE1CLU5eiL0oE8reH7Tg1y99TDM/g== + dependencies: + "@babel/types" "^7.12.13" + "@babel/helper-module-transforms@^7.12.1": version "7.12.1" resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.12.1.tgz#7954fec71f5b32c48e4b303b437c34453fd7247c" @@ -980,6 +987,15 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" +"@babel/types@^7.12.13": + version "7.12.17" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.12.17.tgz#9d711eb807e0934c90b8b1ca0eb1f7230d150963" + integrity sha512-tNMDjcv/4DIcHxErTgwB9q2ZcYyN0sUfgGKUK/mm1FJK7Wz+KstoEekxrl/tBiNDgLK1HGi+sppj1An/1DR4fQ== + dependencies: + "@babel/helper-validator-identifier" "^7.12.11" + lodash "^4.17.19" + to-fast-properties "^2.0.0" + "@hapi/accept@5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@hapi/accept/-/accept-5.0.1.tgz#068553e867f0f63225a506ed74e899441af53e10" @@ -1568,9 +1584,9 @@ babel-plugin-module-resolver@^4.0.0: resolve "^1.13.1" "babel-plugin-superjson-next@file:..": - version "0.1.10" + version "0.2.1" dependencies: - "@babel/helper-module-imports" "^7.12.5" + "@babel/helper-module-imports" "^7.12.13" hoist-non-react-statics "^3.3.2" babel-plugin-syntax-jsx@6.18.0: diff --git a/src/tools.tsx b/src/tools.tsx index d0d5b52..e299b5e 100644 --- a/src/tools.tsx +++ b/src/tools.tsx @@ -3,13 +3,13 @@ import * as hoistNonReactStatics from 'hoist-non-react-statics'; import type { GetServerSideProps } from 'next'; import * as React from 'react'; -type SuperJSONProps = ReturnType & { - _superjson: true; +type SuperJSONProps

= P & { + _superjson?: ReturnType['meta']; }; export function withSuperJSONProps

( gssp: GetServerSideProps

-): GetServerSideProps { +): GetServerSideProps> { return async function withSuperJSON(...args) { const result = await gssp(...args); @@ -18,14 +18,10 @@ export function withSuperJSONProps

( } const { json, meta } = SuperJSON.serialize(result.props); + const props = json as any; - const props: SuperJSONProps = { - json, - _superjson: true, - }; - - if (Boolean(meta)) { - props.meta = meta; + if (meta) { + props._superjson = meta; } return { @@ -37,15 +33,14 @@ export function withSuperJSONProps

( export function withSuperJSONPage

( Page: React.ComponentType

-): React.ComponentType { - function WithSuperJSON(serializedProps: SuperJSONProps) { - if (!serializedProps._superjson) { - const PageWithoutProps = Page as React.ComponentType<{}>; - return ; - } - - const props = SuperJSON.deserialize

(serializedProps); - return ; +): React.ComponentType> { + function WithSuperJSON(serializedProps: SuperJSONProps

) { + const { _superjson, ...props } = serializedProps; + return ( + + ); } hoistNonReactStatics(WithSuperJSON, Page);