Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: next-urql – send App props for pre-pass #2573

Closed
tomvardasca opened this issue Jul 28, 2022 · 4 comments · Fixed by #2909
Closed

RFC: next-urql – send App props for pre-pass #2573

tomvardasca opened this issue Jul 28, 2022 · 4 comments · Fixed by #2909
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@tomvardasca
Copy link

tomvardasca commented Jul 28, 2022

Summary

Using the next-urql library with withUrqlClient is used with ssr: true, all the Next App tree is re-rendered. When we use withUrqlClient in the App everything works fine. But when we use withUrqlClient in pages and have React Context providers in the custom Aapp that receive props from App.getInitialProps. In the pre-pass step, this values (it only fetches the Page.getInitialProps) and no App props from App.getInitialProps. This can be an issue if, for example, we use a Feature Flag React context, the behavior in the pre-pass step will be different.

Proposed Solution

What I want to propose is a callback inside WithUrqlClientOptions where we could send this app props from the Next context, something like:

export interface WithUrqlClientOptions {
  ssr?: boolean;
  neverSuspend?: boolean;
  staleWhileRevalidate?: boolean;
  getAppProps?: (ctx?: NextPageContext) => any;
}

And the only change would be in with-urql-client.ts:

       const appProps = isApp ? {} : options?.getAppProps?.(ctx) ?? {};
       // L: 163 
       const appTreeProps = isApp ? props : { pageProps: props, ...appProps };

With this, we are able to send the app props, and keep using the context in the pre-pass step.

@tomvardasca tomvardasca added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Jul 28, 2022
@nruhe
Copy link

nruhe commented Dec 13, 2022

I believe we're running into a similar issue when trying to use withUrqlClient on _app.js alongside next-i18next's appWithTranslations

@Swiftwork
Copy link

@nruhe I opened an issue related to this but not quite the same regarding next-i18next. #2892

@kitten
Copy link
Member

kitten commented Mar 9, 2023

I have to be honest — I can't keep track of Next's convoluted way of defining their getInitialProps, so to keep it simple, is this obsolete with #2892 being resolved with #2909 having been merged?

@kitten
Copy link
Member

kitten commented Mar 19, 2023

Closing due to inactivity.
Potentially resolved by #2909

@kitten kitten closed this as completed Mar 19, 2023
@kitten kitten linked a pull request Mar 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
4 participants