diff --git a/example/src/pages/film/[id].tsx b/example/src/pages/film/[id].tsx index 8ba426b..7f99bd4 100644 --- a/example/src/pages/film/[id].tsx +++ b/example/src/pages/film/[id].tsx @@ -64,4 +64,10 @@ export default withRelay(Film, FilmQuery, { return createServerEnvironment(); }, + // clientSideProps with arbitrary sleep, + // to show async or async capability + clientSideProps: async () => { + await new Promise(resolve => setTimeout(resolve, 200)); + return {} + } }); diff --git a/src/wired/component.tsx b/src/wired/component.tsx index 71f0d5a..84039f9 100644 --- a/src/wired/component.tsx +++ b/src/wired/component.tsx @@ -52,7 +52,7 @@ export interface WiredOptions { /** Props passed to the component when rendering on the client. */ clientSideProps?: ( ctx: NextPageContext - ) => OrRedirect>; + ) => OrRedirect> | Promise>>; /** Called when creating a Relay environment on the server. */ createServerEnvironment: ( ctx: NextPageContext, @@ -211,14 +211,14 @@ async function getServerInitialProps( }; } -function getClientInitialProps( +async function getClientInitialProps( ctx: NextPageContext, query: GraphQLTaggedNode, opts: WiredOptions ) { const { variablesFromContext = defaultVariablesFromContext } = opts; const clientSideProps = opts.clientSideProps - ? opts.clientSideProps(ctx) + ? await opts.clientSideProps(ctx) : ({} as ClientSideProps); if ('redirect' in clientSideProps) {