Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Fix support for using withUrqlClient with _app.js. #13

Merged
merged 3 commits into from
Jan 1, 2020

Conversation

parkerziegler
Copy link
Contributor

Fix #6

Thanks to @bmathews for finding the needle in the haystack and getting this working πŸŽ‰ Ultimately, the issue here had to do with how the withUrql HoC received the urqlClient from getInitialProps. In the case where we were wrapping a Page component, this was working as expected. getInitialProps would get run, we'd run ssrPrepass on AppTree (in this case, our Page component), and the urqlClient would get passed down via props. βœ…

With _app.js however, things are a bit different. The urqlClient we attach to pageProps is no longer a direct page prop b/c what we're wrapping isn't a Page component, it's the full App component. _app.js gets access to each page's props via pageProps rather than direct props. So, in cases where we wrap _app.js, we need to check pageProps.urqlClient.

This change is in withUrqlClient, which is the only really important file to review. Otherwise, the changes here are just expanding our example directory into an examples directory. It's the same app, but one the first wraps a single Page component while the latter shows how to use next-urql with _app.js. Fortunately for us again, there's no breaking API change in this PR, so we can release this as 0.2.3 πŸŽ‰

Co-authored-by: bmathews <brian.mathews@formidable.com>
Copy link

@kitten kitten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesomeeeeee! βœ¨πŸ‘ we’ve been struggling to narrow this done for a while! Happy to see that this is finally a solution for both approaches/camps of how to use urql with Next!

Copy link
Contributor

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one πŸŽ‰

@parkerziegler parkerziegler merged commit b6540db into master Jan 1, 2020
@parkerziegler parkerziegler deleted the fix/support-_app.js branch January 1, 2020 00:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration with _app.js
4 participants